답안 #876381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876381 2023-11-21T16:10:16 Z vjudge1 Tracks in the Snow (BOI13_tracks) C++17
6.66667 / 100
2000 ms 1048580 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) && tp[u] != '.'){
				adj[v].pb(u);
				adj[u].pb(v);
			}

			if(j < (w-1) && tp[u] != '.'){
				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;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2689 ms 1048580 KB Time limit exceeded
2 Execution timed out 2745 ms 1048576 KB Time limit exceeded
3 Incorrect 149 ms 708100 KB Output isn't correct
4 Correct 170 ms 716112 KB Output is correct
5 Execution timed out 2696 ms 1048576 KB Time limit exceeded
6 Execution timed out 2623 ms 1048576 KB Time limit exceeded
7 Incorrect 147 ms 708280 KB Output isn't correct
8 Correct 150 ms 708452 KB Output is correct
9 Execution timed out 2718 ms 1048576 KB Time limit exceeded
10 Execution timed out 2711 ms 1048576 KB Time limit exceeded
11 Correct 160 ms 710472 KB Output is correct
12 Execution timed out 2608 ms 1048576 KB Time limit exceeded
13 Execution timed out 2751 ms 1048576 KB Time limit exceeded
14 Execution timed out 2729 ms 1048576 KB Time limit exceeded
15 Execution timed out 2750 ms 1048576 KB Time limit exceeded
16 Execution timed out 2730 ms 1048576 KB Time limit exceeded
17 Execution timed out 2761 ms 1048576 KB Time limit exceeded
18 Correct 169 ms 716124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2655 ms 1048576 KB Time limit exceeded
2 Execution timed out 2738 ms 1048576 KB Time limit exceeded
3 Incorrect 1110 ms 1017684 KB Output isn't correct
4 Execution timed out 2758 ms 1048576 KB Time limit exceeded
5 Runtime error 806 ms 1048576 KB Execution killed with signal 9
6 Runtime error 925 ms 1048576 KB Execution killed with signal 9
7 Execution timed out 2813 ms 1048576 KB Time limit exceeded
8 Execution timed out 2699 ms 1048576 KB Time limit exceeded
9 Execution timed out 2766 ms 1048580 KB Time limit exceeded
10 Incorrect 149 ms 709200 KB Output isn't correct
11 Execution timed out 2785 ms 1048576 KB Time limit exceeded
12 Incorrect 160 ms 708896 KB Output isn't correct
13 Execution timed out 2696 ms 1048576 KB Time limit exceeded
14 Execution timed out 2765 ms 1048576 KB Time limit exceeded
15 Execution timed out 2721 ms 1048576 KB Time limit exceeded
16 Incorrect 231 ms 730856 KB Output isn't correct
17 Execution timed out 2776 ms 1048576 KB Time limit exceeded
18 Execution timed out 2735 ms 1048576 KB Time limit exceeded
19 Execution timed out 2699 ms 1048576 KB Time limit exceeded
20 Execution timed out 2742 ms 1048576 KB Time limit exceeded
21 Incorrect 781 ms 890872 KB Output isn't correct
22 Runtime error 820 ms 1048576 KB Execution killed with signal 9
23 Incorrect 944 ms 941208 KB Output isn't correct
24 Incorrect 874 ms 969296 KB Output isn't correct
25 Runtime error 807 ms 1048576 KB Execution killed with signal 9
26 Runtime error 937 ms 1048576 KB Execution killed with signal 9
27 Runtime error 922 ms 1048576 KB Execution killed with signal 9
28 Runtime error 915 ms 1048576 KB Execution killed with signal 9
29 Runtime error 919 ms 1048576 KB Execution killed with signal 9
30 Runtime error 909 ms 1048576 KB Execution killed with signal 9
31 Runtime error 937 ms 1048576 KB Execution killed with signal 9
32 Runtime error 971 ms 1048576 KB Execution killed with signal 9