Submission #449924

#TimeUsernameProblemLanguageResultExecution timeMemory
449924fuad27Tracks in the Snow (BOI13_tracks)C++14
11.67 / 100
2141 ms1048580 KiB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optmize("Ofast")
#pragma GCC target("avx,avx2,fma")
int h, w, ans = 0;
vector<vector<char>> v;
vector<vector<bool>> visited(h, vector<bool> (w, 0));
void dfs(vector<vector<char>> &v, int i, int j, char k) {
if(i < 0 or j < 0  or i >= h or j >=w or v[i][j] == '.' or (v[i][j] != '#' and v[i][j] != k) or visited[i][j])return;
else {
	v[i][j] = '#';
	visited[i][j] = true;
	if(i < h-1 and !visited[i+1][j])
		dfs(v, i+1, j, k);
	if(i and !visited[i-1][j])
		dfs(v, i-1, j, k);
	if(j < w-1 and !visited[i][j+1])
		dfs(v, i, j+1, k);
	if(j and !visited[i][j-1])
		dfs(v, i, j-1, k);	
}
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> h >> w;
v.resize(h, vector<char> (w));
for(int i = 0;i<h;i++) {
	for(int j = 0;j<w;j++) {
		cin >> v[i][j];
	}
}
queue<pair<int, int>> q;
q.push({0, 0});
vector<vector<int>> visi(h, vector<int>(w, 0));
while(!q.empty()) {
	int x = q.front().first;
	int y = q.front().second;
	q.pop();
	if(v[x][y]!='.') {
		visited.assign(h, vector<bool> (w, 0));
		if(x and !visi[x-1][y]) {
			q.push({x-1, y});
			visi[x-1][y] = 1;
		}
		if(y and !visi[x][y]) {
			q.push({x, y-1});
			visi[x][y-1] = 1;
		}
		if(x < h-1 and !visi[x+1][y]) {
			q.push({x+1, y});
			visi[x+1][y] = 1;
		}
		if(y < w -1 and !visi[x][y+1]) {
			q.push({x, y+1});
			visi[x][y+1] = 1;
		}
		if(v[x][y] != '#') {
		dfs(v, x, y, v[x][y]);
		ans++;
	}
	visi[x][y] = 1;
}
}
cout<<ans<<endl;

}

Compilation message (stderr)

tracks.cpp:3: warning: ignoring '#pragma GCC optmize' [-Wunknown-pragmas]
    3 | #pragma GCC optmize("Ofast")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...