Skip to content

Commit 121a201

Browse files
committed
all
1 parent 6db4d2b commit 121a201

File tree

9 files changed

+99956
-6
lines changed

9 files changed

+99956
-6
lines changed

codeforces/round232/div1/d.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ void init(){
2323
for(i = 2 ; i < MAXN; ++ i) {
2424
lld t ;
2525
if (i % 2 == 0 )
26-
t = i / 2 * (i - 1) ;
26+
t = i / 2 * (i - 1) % BIG_PRIME ;
2727
else
28-
t = ( i - 1) / 2 * i ;
28+
t = ( i - 1) / 2 * i % BIG_PRIME ;
2929
invs[i] = ( ( i * invs[i-1] ) % BIG_PRIME + ( fac[i-1] * t ) % BIG_PRIME ) % BIG_PRIME ;
3030
}
3131
//for(i = 1 ; i <= 6 ; ++ i) printf("invs[%lld]=%lld\n", i, invs[i]) ;
@@ -37,13 +37,13 @@ lld lowbit(lld x){
3737

3838
void insert(lld x, lld del){
3939
for(lld i = x ; i <= n ; i += lowbit(i))
40-
bit[i] += del;
40+
bit[i] = (bit[i] + del) % BIG_PRIME ;
4141
}
4242

4343
lld sum(lld x){
4444
lld ans = 0 ;
4545
for(lld i = x; i>=1 ; i -=lowbit(i))
46-
ans += bit[i] ;
46+
ans = (ans + bit[i]) % BIG_PRIME ;
4747
return ans ;
4848
}
4949

@@ -57,10 +57,11 @@ int main(){
5757
result = 0 ;
5858
memset(bit, 0 , sizeof(bit)) ;
5959
lld sv = 0 , t, b;
60+
6061
for(i = 1 ; i <= n; ++ i){
6162
// from [i+1..n]
62-
b = p[i] - 1 - sum(p[i]);
63-
result = (result + b * invs[n - i]) % BIG_PRIME ;
63+
b = ( p[i] - 1 - sum(p[i]) ) % BIG_PRIME ;
64+
result = (result + b * invs[n - i] % BIG_PRIME ) % BIG_PRIME ;
6465
// from [i..i]
6566
lld tb = b * (b - 1) / 2 % BIG_PRIME ;
6667
result = (result + tb * fac[n - i] % BIG_PRIME ) % BIG_PRIME ;

codeforces/round234/a.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
#include<stdlib.h>
4+
#include<algorithm>
5+
#include<vector>
6+
7+
using namespace std;
8+
9+
int main(){
10+
int t ;
11+
char s[13];
12+
scanf("%d", &t);
13+
while(t--){
14+
vector< pair<int,int> > vec ;
15+
16+
vec.clear();
17+
scanf("%s", s);
18+
19+
for(int i = 1 ; i <= 12; ++ i)
20+
if(12 % i == 0){
21+
bool check = 0 ;
22+
int x = i, y = 12 / i ;
23+
for(int c = 0 ; c < y ; ++ c)
24+
{
25+
bool allx = 1 ;
26+
for(int r = 0 ; r < x ; ++ r)
27+
if(s[r * y + c] != 'X')
28+
{
29+
allx = 0 ;
30+
break;
31+
}
32+
if (allx == 1){
33+
check = 1 ;
34+
break;
35+
}
36+
}
37+
if(check)
38+
{
39+
vec.push_back( pair<int,int>(x, y) ) ;
40+
}
41+
}
42+
43+
printf("%d", (int)vec.size());
44+
for(int i = 0 ; i < vec.size(); ++ i){
45+
pair<int, int> p = vec[i];
46+
printf(" %dx%d", p.first, p.second);
47+
}
48+
printf("\n");
49+
}
50+
return 0 ;
51+
}

codeforces/round234/a.out

13.2 KB
Binary file not shown.

codeforces/round234/b.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include<iostream>
2+
#include<stdio.h>
3+
#include<stdlib.h>
4+
#include<vector>
5+
#include<string.h>
6+
7+
using namespace std;
8+
9+
#define PII pair<int, int>
10+
11+
int main(){
12+
int n , m, no_ans, i, j;
13+
char bd[1001][1001];
14+
vector<PII> vec ;
15+
int flag[1001];
16+
17+
while(scanf("%d%d", &n, &m)!=EOF){
18+
19+
for(i = 0 ; i < n ; ++ i)
20+
scanf("%s", bd[i]);
21+
22+
no_ans = 0 ;
23+
vec.clear();
24+
25+
memset(flag, 0 , sizeof(flag)) ;
26+
27+
for(i = 0 ; i < n && !no_ans; ++ i)
28+
{
29+
int cnt = -1 ;
30+
for(j = 0 ; j <m && !no_ans ; ++ j)
31+
if(bd[i][j] == 'G') {
32+
cnt = 0 ;
33+
vec.push_back(PII(i, j));
34+
}else if (bd[i][j] == 'S') {
35+
if(cnt ==-1)
36+
no_ans = 1 ;
37+
}
38+
}
39+
if(no_ans){
40+
printf("-1\n") ;
41+
continue;
42+
}
43+
44+
int ans = 0 ;
45+
bool finished = 1 ;
46+
do{
47+
finished = 1;
48+
bool touch = 0 ;
49+
for(i = 0 ; i < vec.size() ; ++ i)
50+
if (!flag[i]){
51+
finished = 0;
52+
if( ++vec[i].second >= m || bd[vec[i].first][vec[i].second] == 'S') {
53+
flag[i] = 1;
54+
touch = 1 ;
55+
}
56+
}
57+
if(touch)
58+
ans ++ ;
59+
if(finished) break;
60+
}while(1) ;
61+
printf("%d\n", ans) ;
62+
}
63+
return 0 ;
64+
}
65+

codeforces/round234/b.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
3 4
2+
*G*S
3+
G**S
4+
*G*S
5+
6+
7+
1 3
8+
S*G
9+
10+
11+
3 3
12+
G*S
13+
*GS
14+
GS*

codeforces/round234/c.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include<iostream>
2+
#include<stdlib.h>
3+
#include<string.h>
4+
#include<stdio.h>
5+
using namespace std;
6+
7+
int main(){
8+
int n , m , x , y , z, p , px[100001], py[100001], tx , ty;
9+
while(cin >> n >> m >> x >> y >> z >> p){
10+
for(int i = 0 ; i < p ; ++ i){
11+
cin >> px[i] >> py[i] ;
12+
px[i] -- ; py[i] -- ;
13+
}
14+
x %= 4 ; y %= 2 ; z %= 4 ;
15+
for(int i = 0 ; i < p ; ++ i){
16+
tx = px[i] ; ty = py[i] ;
17+
if(x == 1){
18+
px[i] = ty ; py[i] = n - 1 - tx ;
19+
}else if(x == 2){
20+
px[i] = n - 1 - tx ; py[i] = m - 1 - ty ;
21+
}else if (x == 3){
22+
px[i] = m - 1 - ty ; py[i] = tx ;
23+
}
24+
tx = px[i] ; ty = py[i] ;
25+
if(y == 1){
26+
px[i] = tx ; py[i] = m - 1 - ty ;
27+
}
28+
tx = px[i] ; ty = py[i] ;
29+
if(z == 3){
30+
px[i] = ty ; py[i] = n - 1 - tx ;
31+
}else if (z == 2){
32+
px[i] = n - 1 - tx ; py[i] = m - 1 - ty ;
33+
}else if (z == 1){
34+
px[i] = m - 1 - ty ; py[i] = tx ;
35+
}
36+
}
37+
for(int i = 0 ; i < p ; ++ i ){
38+
printf("%d %d\n", px[i] + 1, py[i] + 1);
39+
}
40+
}
41+
return 0 ;
42+
}

codeforces/round234/d.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#include<iostream>
2+
#include<stdio.h>
3+
#include<stdlib.h>
4+
#include<string.h>
5+
6+
using namespace std ;
7+
#define MAXN 100001
8+
9+
10+
typedef struct node{
11+
int e, v, next ;
12+
}node;
13+
14+
int n , m , k , c[MAXN], part[MAXN], dist[505][505];
15+
int sz , visit[MAXN], gh[MAXN];
16+
node edge[4 * MAXN];
17+
18+
void add_edge(int u, int v, int x){
19+
edge[sz].e = v ; edge[sz].v = x ; edge[sz].next = gh[u];
20+
gh[u] = sz; sz ++ ;
21+
22+
edge[sz].e = u ; edge[sz].v = x ; edge[sz].next = gh[v];
23+
gh[v] = sz; sz ++ ;
24+
}
25+
26+
void dfs(int s, int part_id){
27+
part[s] = part_id ;
28+
visit[s] = 1 ;
29+
for(int i = gh[s]; i != -1 ; i = edge[i].next ){
30+
int e = edge[i].e ;
31+
if(visit[e] == 0 && edge[i].v == 0 )
32+
dfs(e, part_id);
33+
}
34+
}
35+
36+
int main(){
37+
int correct;
38+
while(scanf("%d%d%d", &n , &m , &k) !=EOF ){
39+
sz = 0 ;
40+
memset(gh, -1, sizeof(gh));
41+
for(int i = 0 ; i < k ; ++ i) scanf("%d", &c[i]) ;
42+
43+
for(int i = 0 ; i < m ; ++ i){
44+
int u, v, x;
45+
scanf("%d%d%d", &u, &v, &x) ;
46+
add_edge(u, v , x);
47+
}
48+
49+
int part_id = 0 ;
50+
memset(visit, 0 , sizeof(visit));
51+
for(int i = 1 ; i <= n; ++ i )
52+
if(visit[i] == 0){
53+
dfs(i, ++part_id);
54+
}
55+
56+
correct = (part_id <= k) ;
57+
58+
int sum = 0 ;
59+
for(int i = 0 ; i < k && correct; ++ i){
60+
sum += c[i];
61+
int part_j = part[ sum - c[i] + 1 ];
62+
for(int j = sum - c[i] + 1 ; j <= sum; ++ j)
63+
correct = part[j] == part_j;
64+
}
65+
66+
if(!correct){
67+
printf("No\n");
68+
continue ;
69+
}
70+
71+
memset(dist, -1, sizeof(dist));
72+
for(int i = 1; i <=n ; ++ i) dist[i][i] = 0 ;
73+
for(int i = 1; i <= n ; ++ i){
74+
for(int t = gh[i]; t != -1; t = edge[t].next ){
75+
int s = part[i] , e = part[edge[t].e] , val = edge[t].v;
76+
if(dist[s][e] == -1 || dist[e][s] == -1){
77+
dist[s][e] = dist[e][s] = val ;
78+
}else{
79+
dist[s][e] = dist[e][s] = min(dist[s][e], val);
80+
}
81+
}
82+
}
83+
84+
for(int t = 1 ; t <= k ; ++ t){
85+
for(int i = 1 ; i <= k; ++ i )
86+
for(int j = 1; j <= k ; ++ j){
87+
if(dist[i][j] == -1){
88+
if(dist[i][t] != -1 && dist[t][j] != -1)
89+
dist[i][j] = dist[i][t] + dist[t][j] ;
90+
}else{
91+
if(dist[i][t] != -1 && dist[t][j] != -1 && dist[i][j] > dist[i][t] + dist[t][j])
92+
dist[i][j] = dist[i][t] + dist[t][j];
93+
}
94+
}
95+
}
96+
97+
printf("Yes\n");
98+
for(int i = 1 ; i <=k ; ++ i){
99+
printf("%d", dist[i][1]);
100+
for(int j = 2; j <=k ; ++ j)
101+
printf(" %d", dist[i][j]);
102+
printf("\n");
103+
}
104+
}
105+
return 0 ;
106+
}

0 commit comments

Comments
 (0)