#include <iostream>
#include <vector>
#define pb push_back
#define endl '\n'
using namespace std;
const int MAXN = 3e7+100;
vector<int> adj[MAXN];
char tp[MAXN];
int h, w, n;
string mat[4010];
int cnt;
bool used[MAXN];
void dfs(int v, int ld){
cout << v << endl;
used[v] = 1;
for(int u : adj[v]){
if(used[u]) continue;
if(tp[u] == tp[v] || tp[u] == '-' || tp[v] == '-') dfs(u, ld);
else if(tp[v] != '-'){
adj[u].pb(n+ld);
adj[n+ld].pb(u);
// cout << u << "<->" << n+ld << endl;
}
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin >> h >> w;
n = h*w;
for(int i=0;i<h; i++) cin >> mat[i];
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
int v, u, u_;
v = (i*w) + j;
u = (i+1)*w + j;
u_ = i*w + j + 1;
if(tp[v] == '.') continue;
if(i < (h-1) && tp[u] != '.'){
adj[v].pb(u);
adj[u].pb(v);
}
if(j < (w-1) && tp[u] != '.'){
adj[v].pb(u_);
adj[u_].pb(v);
}
tp[v] = mat[i][j];
}
}
for(int i=0; i<n; i++){
if(used[i] || tp[i] == '.') continue;
used[i] = 1;
tp[cnt + n] = '-';
dfs(i, cnt);
cnt++;
}
cout << cnt << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2631 ms |
1048576 KB |
Time limit exceeded |
2 |
Execution timed out |
2680 ms |
1048576 KB |
Time limit exceeded |
3 |
Execution timed out |
2715 ms |
1048576 KB |
Time limit exceeded |
4 |
Incorrect |
186 ms |
717396 KB |
Output isn't correct |
5 |
Execution timed out |
2630 ms |
1048576 KB |
Time limit exceeded |
6 |
Execution timed out |
2718 ms |
1048576 KB |
Time limit exceeded |
7 |
Execution timed out |
2697 ms |
1048576 KB |
Time limit exceeded |
8 |
Incorrect |
149 ms |
708436 KB |
Output isn't correct |
9 |
Execution timed out |
2724 ms |
1048576 KB |
Time limit exceeded |
10 |
Incorrect |
176 ms |
712276 KB |
Output isn't correct |
11 |
Incorrect |
156 ms |
710836 KB |
Output isn't correct |
12 |
Execution timed out |
2800 ms |
1048576 KB |
Time limit exceeded |
13 |
Execution timed out |
2711 ms |
1048576 KB |
Time limit exceeded |
14 |
Execution timed out |
2746 ms |
1048576 KB |
Time limit exceeded |
15 |
Incorrect |
209 ms |
722724 KB |
Output isn't correct |
16 |
Execution timed out |
2608 ms |
1048576 KB |
Time limit exceeded |
17 |
Execution timed out |
2726 ms |
1048576 KB |
Time limit exceeded |
18 |
Incorrect |
181 ms |
717392 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2719 ms |
1048576 KB |
Time limit exceeded |
2 |
Incorrect |
507 ms |
797144 KB |
Output isn't correct |
3 |
Runtime error |
953 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Execution timed out |
2839 ms |
1048576 KB |
Time limit exceeded |
5 |
Runtime error |
1045 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Runtime error |
917 ms |
1048576 KB |
Execution killed with signal 9 |
7 |
Execution timed out |
2746 ms |
1048576 KB |
Time limit exceeded |
8 |
Execution timed out |
2788 ms |
1048576 KB |
Time limit exceeded |
9 |
Execution timed out |
2742 ms |
1048576 KB |
Time limit exceeded |
10 |
Incorrect |
160 ms |
711760 KB |
Output isn't correct |
11 |
Incorrect |
158 ms |
711248 KB |
Output isn't correct |
12 |
Incorrect |
155 ms |
709720 KB |
Output isn't correct |
13 |
Incorrect |
493 ms |
796396 KB |
Output isn't correct |
14 |
Execution timed out |
2792 ms |
1048576 KB |
Time limit exceeded |
15 |
Execution timed out |
2967 ms |
1048576 KB |
Time limit exceeded |
16 |
Execution timed out |
2744 ms |
1048576 KB |
Time limit exceeded |
17 |
Execution timed out |
2894 ms |
1048576 KB |
Time limit exceeded |
18 |
Runtime error |
1502 ms |
1048580 KB |
Execution killed with signal 9 |
19 |
Execution timed out |
3015 ms |
1048576 KB |
Time limit exceeded |
20 |
Execution timed out |
2733 ms |
1048576 KB |
Time limit exceeded |
21 |
Runtime error |
1088 ms |
1048576 KB |
Execution killed with signal 9 |
22 |
Runtime error |
959 ms |
1048576 KB |
Execution killed with signal 9 |
23 |
Execution timed out |
3091 ms |
1048576 KB |
Time limit exceeded |
24 |
Runtime error |
897 ms |
1048576 KB |
Execution killed with signal 9 |
25 |
Runtime error |
935 ms |
1048576 KB |
Execution killed with signal 9 |
26 |
Runtime error |
922 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Runtime error |
917 ms |
1048576 KB |
Execution killed with signal 9 |
28 |
Runtime error |
903 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Runtime error |
897 ms |
1048576 KB |
Execution killed with signal 9 |
30 |
Runtime error |
837 ms |
1048576 KB |
Execution killed with signal 9 |
31 |
Runtime error |
940 ms |
1048576 KB |
Execution killed with signal 9 |
32 |
Runtime error |
893 ms |
1048576 KB |
Execution killed with signal 9 |