#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <random>
#include <chrono>
#include <vector>
#include <array>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxn = 3000, k = 4, mxt = 100000, w = 3;
const char c[w + k] = {'R', 'G', 'W', '/', '|', '\\', '-'};
typedef pair<array<pi, w>, int> T;
int n, m;
int a[mxn][mxn], vis[mxn][mxn];
vector<T> v;
int dx[2 * k] = {1, 1, 1, 0, -1, -1, -1, 0};
int dy[2 * k] = {-1, 0, 1, 1, 1, 0, -1, -1};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++){
char x;
cin >> x;
a[i][j] = find(c, c + w, x) - c;
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++){
if(!~-a[i][j]){
for(int p = k + 1; p < 2 * k; p += 2){
v.push_back(T());
v.back().f[1] = {i, j}, v.back().s = w + p % k;
for(int l = 0; l < 2; l++){
int x = i + dx[(p + l * k) % (2 * k)], y = j + dy[(p + l * k) % (2 * k)];
if(x >= 0 && y >= 0 && x < n && y < m && a[x][y] == 2 * l){
v.back().f[2 * l] = {x, y};
}else{
v.pop_back();
break;
}
}
}
}
}
int ret = 0;
if(v.empty()) goto hell;
memset(vis, -1, sizeof(vis));
for(int t = 0, tt = 0; t < mxt; t += tt){
int it = uniform_int_distribution<int>(0, v.size() - 1)(rng);
int x = -1;
for(pi i : v[it].f){
if(~vis[i.f][i.s]){
if(!~x) x = vis[i.f][i.s];
else x = -2;
}
}
if(x != -2 && x != it){
if(~x){
for(pi i : v[x].f) vis[i.f][i.s] = -1;
a[v[x].f[1].f][v[x].f[1].s] = 1;
}
for(pi i : v[it].f) vis[i.f][i.s] = it;
a[v[it].f[1].f][v[it].f[1].s] = v[it].s;
ret += !~x;
if(tt && !~x) t = 0;
}else if(!tt){
tt = 1;
}
}
hell:
cout << ret << endl;
/*
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++) cout << c[a[i][j]];
cout << endl;
}
*/
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
24 ms |
35456 KB |
Output is correct |
7 |
Correct |
23 ms |
35620 KB |
Output is correct |
8 |
Correct |
25 ms |
35584 KB |
Output is correct |
9 |
Correct |
24 ms |
35584 KB |
Output is correct |
10 |
Correct |
22 ms |
35584 KB |
Output is correct |
11 |
Correct |
24 ms |
35584 KB |
Output is correct |
12 |
Correct |
23 ms |
35584 KB |
Output is correct |
13 |
Correct |
23 ms |
35584 KB |
Output is correct |
14 |
Correct |
22 ms |
35576 KB |
Output is correct |
15 |
Correct |
21 ms |
35584 KB |
Output is correct |
16 |
Correct |
24 ms |
35584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
24 ms |
35456 KB |
Output is correct |
7 |
Correct |
23 ms |
35620 KB |
Output is correct |
8 |
Correct |
25 ms |
35584 KB |
Output is correct |
9 |
Correct |
24 ms |
35584 KB |
Output is correct |
10 |
Correct |
22 ms |
35584 KB |
Output is correct |
11 |
Correct |
24 ms |
35584 KB |
Output is correct |
12 |
Correct |
23 ms |
35584 KB |
Output is correct |
13 |
Correct |
23 ms |
35584 KB |
Output is correct |
14 |
Correct |
22 ms |
35576 KB |
Output is correct |
15 |
Correct |
21 ms |
35584 KB |
Output is correct |
16 |
Correct |
24 ms |
35584 KB |
Output is correct |
17 |
Correct |
23 ms |
35544 KB |
Output is correct |
18 |
Correct |
21 ms |
35584 KB |
Output is correct |
19 |
Correct |
22 ms |
35584 KB |
Output is correct |
20 |
Correct |
21 ms |
35584 KB |
Output is correct |
21 |
Correct |
22 ms |
35584 KB |
Output is correct |
22 |
Correct |
23 ms |
35584 KB |
Output is correct |
23 |
Correct |
22 ms |
35576 KB |
Output is correct |
24 |
Correct |
22 ms |
35584 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
22 ms |
35584 KB |
Output is correct |
28 |
Correct |
22 ms |
35584 KB |
Output is correct |
29 |
Correct |
23 ms |
35584 KB |
Output is correct |
30 |
Correct |
22 ms |
35584 KB |
Output is correct |
31 |
Correct |
21 ms |
35584 KB |
Output is correct |
32 |
Correct |
23 ms |
35712 KB |
Output is correct |
33 |
Correct |
23 ms |
35584 KB |
Output is correct |
34 |
Correct |
23 ms |
35584 KB |
Output is correct |
35 |
Correct |
23 ms |
35584 KB |
Output is correct |
36 |
Correct |
23 ms |
35576 KB |
Output is correct |
37 |
Correct |
22 ms |
35576 KB |
Output is correct |
38 |
Correct |
22 ms |
35584 KB |
Output is correct |
39 |
Correct |
23 ms |
35584 KB |
Output is correct |
40 |
Correct |
23 ms |
35576 KB |
Output is correct |
41 |
Correct |
22 ms |
35584 KB |
Output is correct |
42 |
Correct |
22 ms |
35584 KB |
Output is correct |
43 |
Correct |
23 ms |
35584 KB |
Output is correct |
44 |
Correct |
22 ms |
35584 KB |
Output is correct |
45 |
Correct |
23 ms |
35584 KB |
Output is correct |
46 |
Correct |
22 ms |
35584 KB |
Output is correct |
47 |
Correct |
22 ms |
35584 KB |
Output is correct |
48 |
Correct |
22 ms |
35584 KB |
Output is correct |
49 |
Correct |
22 ms |
35576 KB |
Output is correct |
50 |
Correct |
23 ms |
35584 KB |
Output is correct |
51 |
Correct |
23 ms |
35584 KB |
Output is correct |
52 |
Correct |
22 ms |
35584 KB |
Output is correct |
53 |
Correct |
22 ms |
35576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
24 ms |
35456 KB |
Output is correct |
7 |
Correct |
23 ms |
35620 KB |
Output is correct |
8 |
Correct |
25 ms |
35584 KB |
Output is correct |
9 |
Correct |
24 ms |
35584 KB |
Output is correct |
10 |
Correct |
22 ms |
35584 KB |
Output is correct |
11 |
Correct |
24 ms |
35584 KB |
Output is correct |
12 |
Correct |
23 ms |
35584 KB |
Output is correct |
13 |
Correct |
23 ms |
35584 KB |
Output is correct |
14 |
Correct |
22 ms |
35576 KB |
Output is correct |
15 |
Correct |
21 ms |
35584 KB |
Output is correct |
16 |
Correct |
24 ms |
35584 KB |
Output is correct |
17 |
Correct |
23 ms |
35544 KB |
Output is correct |
18 |
Correct |
21 ms |
35584 KB |
Output is correct |
19 |
Correct |
22 ms |
35584 KB |
Output is correct |
20 |
Correct |
21 ms |
35584 KB |
Output is correct |
21 |
Correct |
22 ms |
35584 KB |
Output is correct |
22 |
Correct |
23 ms |
35584 KB |
Output is correct |
23 |
Correct |
22 ms |
35576 KB |
Output is correct |
24 |
Correct |
22 ms |
35584 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
22 ms |
35584 KB |
Output is correct |
28 |
Correct |
22 ms |
35584 KB |
Output is correct |
29 |
Correct |
23 ms |
35584 KB |
Output is correct |
30 |
Correct |
22 ms |
35584 KB |
Output is correct |
31 |
Correct |
21 ms |
35584 KB |
Output is correct |
32 |
Correct |
23 ms |
35712 KB |
Output is correct |
33 |
Correct |
23 ms |
35584 KB |
Output is correct |
34 |
Correct |
23 ms |
35584 KB |
Output is correct |
35 |
Correct |
23 ms |
35584 KB |
Output is correct |
36 |
Correct |
23 ms |
35576 KB |
Output is correct |
37 |
Correct |
22 ms |
35576 KB |
Output is correct |
38 |
Correct |
22 ms |
35584 KB |
Output is correct |
39 |
Correct |
23 ms |
35584 KB |
Output is correct |
40 |
Correct |
23 ms |
35576 KB |
Output is correct |
41 |
Correct |
22 ms |
35584 KB |
Output is correct |
42 |
Correct |
22 ms |
35584 KB |
Output is correct |
43 |
Correct |
23 ms |
35584 KB |
Output is correct |
44 |
Correct |
22 ms |
35584 KB |
Output is correct |
45 |
Correct |
23 ms |
35584 KB |
Output is correct |
46 |
Correct |
22 ms |
35584 KB |
Output is correct |
47 |
Correct |
22 ms |
35584 KB |
Output is correct |
48 |
Correct |
22 ms |
35584 KB |
Output is correct |
49 |
Correct |
22 ms |
35576 KB |
Output is correct |
50 |
Correct |
23 ms |
35584 KB |
Output is correct |
51 |
Correct |
23 ms |
35584 KB |
Output is correct |
52 |
Correct |
22 ms |
35584 KB |
Output is correct |
53 |
Correct |
22 ms |
35576 KB |
Output is correct |
54 |
Correct |
21 ms |
35576 KB |
Output is correct |
55 |
Correct |
27 ms |
47616 KB |
Output is correct |
56 |
Correct |
25 ms |
35832 KB |
Output is correct |
57 |
Correct |
34 ms |
44032 KB |
Output is correct |
58 |
Correct |
185 ms |
45840 KB |
Output is correct |
59 |
Incorrect |
1981 ms |
91304 KB |
Output isn't correct |
60 |
Halted |
0 ms |
0 KB |
- |