Submission #566199

#TimeUsernameProblemLanguageResultExecution timeMemory
566199GusterGoose27Dango Maker (JOI18_dango_maker)C++11
13 / 100
161 ms212184 KiB
#include <iostream> #include <vector> using namespace std; const int MAXN = 3000; int val[MAXN][MAXN]; // 0 red, 1 g, 2 w int n, m; int uf[2*MAXN*MAXN]; // cuz im lazy int size[2*MAXN*MAXN]; vector<int> common[MAXN*MAXN]; int to_id[2*MAXN*MAXN]; int find(int i) { if (uf[i] == -1) return i; return (uf[i] = find(uf[i])); } void merge(int a, int b) { int ida = find(a); int idb = find(b); if (ida == idb) return; size[ida] += size[idb]; uf[idb] = ida; } bool is_vertical(int i, int j) { if (i >= n-2) return 0; return (val[i][j] == 0 && val[i+1][j] == 1 && val[i+2][j] == 2); } bool is_horizontal(int i, int j) { if (j >= m-2) return 0; return (val[i][j] == 0 && val[i][j+1] == 1 && val[i][j+2] == 2); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < m; j++) { if (s[j] == 'R') val[i][j] = 0; if (s[j] == 'G') val[i][j] = 1; if (s[j] == 'W') val[i][j] = 2; } } vector<int> actual_values; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int chash = i*MAXN+j; if (is_vertical(i, j)) { actual_values.push_back(chash); to_id[chash] = actual_values.size()-1; size[chash] = 1; uf[chash] = -1; common[chash].push_back(chash); common[chash+MAXN].push_back(chash); common[chash+2*MAXN].push_back(chash); } if (is_horizontal(i, j)) { actual_values.push_back(chash+MAXN*MAXN); to_id[chash+MAXN*MAXN] = actual_values.size()-1; size[chash+MAXN*MAXN] = 1; uf[chash+MAXN*MAXN] = -1; common[chash].push_back(chash+MAXN*MAXN); common[chash+1].push_back(chash+MAXN*MAXN); common[chash+2].push_back(chash+MAXN*MAXN); } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (common[i*MAXN+j].size() == 2) { merge(common[i*MAXN+j][0], common[i*MAXN+j][1]); } } } int answ = 0; for (int i = 0; i < 2*MAXN*MAXN; i++) { if (uf[i] == -1) answ += (size[i]+1)/2; } cout << answ << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...