Submission #876388

# Submission time Handle Problem Language Result Execution time Memory
876388 2023-11-21T16:21:58 Z vjudge1 Tracks in the Snow (BOI13_tracks) C++17
13.3333 / 100
1390 ms 1048576 KB
#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 << ld << ' ' << 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;

			tp[v] = mat[i][j];

			if(tp[v] == '.') continue;
			
			if(i < (h-1) && mat[i+1][j] != '.'){
				adj[v].pb(u);
				adj[u].pb(v);
			}

			if(j < (w-1) && mat[i][j+1] != '.'){
				adj[v].pb(u_);
				adj[u_].pb(v);
			}
			
		}
	}

	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;
}
# Verdict Execution time Memory Grader output
1 Correct 234 ms 720208 KB Output is correct
2 Incorrect 148 ms 708200 KB Output isn't correct
3 Incorrect 154 ms 708032 KB Output isn't correct
4 Correct 172 ms 716120 KB Output is correct
5 Incorrect 152 ms 708952 KB Output isn't correct
6 Incorrect 150 ms 708180 KB Output isn't correct
7 Incorrect 154 ms 708252 KB Output isn't correct
8 Correct 152 ms 708360 KB Output is correct
9 Incorrect 152 ms 708176 KB Output isn't correct
10 Incorrect 152 ms 709528 KB Output isn't correct
11 Correct 158 ms 710368 KB Output is correct
12 Correct 167 ms 712316 KB Output is correct
13 Incorrect 155 ms 708992 KB Output isn't correct
14 Incorrect 152 ms 708944 KB Output isn't correct
15 Correct 184 ms 717428 KB Output is correct
16 Correct 200 ms 720216 KB Output is correct
17 Incorrect 174 ms 713300 KB Output isn't correct
18 Correct 179 ms 716180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 155 ms 709108 KB Output isn't correct
2 Incorrect 269 ms 742544 KB Output isn't correct
3 Incorrect 798 ms 914272 KB Output isn't correct
4 Incorrect 302 ms 741712 KB Output isn't correct
5 Incorrect 773 ms 950880 KB Output isn't correct
6 Runtime error 964 ms 1048576 KB Execution killed with signal 9
7 Incorrect 149 ms 708948 KB Output isn't correct
8 Incorrect 154 ms 709244 KB Output isn't correct
9 Incorrect 155 ms 709976 KB Output isn't correct
10 Incorrect 149 ms 708692 KB Output isn't correct
11 Incorrect 151 ms 708704 KB Output isn't correct
12 Incorrect 150 ms 708792 KB Output isn't correct
13 Incorrect 276 ms 742484 KB Output isn't correct
14 Incorrect 215 ms 726864 KB Output isn't correct
15 Incorrect 212 ms 721488 KB Output isn't correct
16 Incorrect 212 ms 725840 KB Output isn't correct
17 Incorrect 444 ms 792884 KB Output isn't correct
18 Incorrect 412 ms 764212 KB Output isn't correct
19 Incorrect 297 ms 741756 KB Output isn't correct
20 Incorrect 299 ms 754348 KB Output isn't correct
21 Incorrect 531 ms 829124 KB Output isn't correct
22 Incorrect 762 ms 950860 KB Output isn't correct
23 Incorrect 738 ms 873844 KB Output isn't correct
24 Incorrect 511 ms 853844 KB Output isn't correct
25 Incorrect 1390 ms 938176 KB Output isn't correct
26 Runtime error 927 ms 1048576 KB Execution killed with signal 9
27 Runtime error 939 ms 1048576 KB Execution killed with signal 9
28 Runtime error 921 ms 1048576 KB Execution killed with signal 9
29 Runtime error 927 ms 1048576 KB Execution killed with signal 9
30 Runtime error 929 ms 1048576 KB Execution killed with signal 9
31 Runtime error 948 ms 1048576 KB Execution killed with signal 9
32 Runtime error 998 ms 1048576 KB Execution killed with signal 9