Submission #531204

#TimeUsernameProblemLanguageResultExecution timeMemory
531204zxcvbnmDango Maker (JOI18_dango_maker)C++14
33 / 100
2071 ms262148 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int nax = 3005; char mat[nax][nax]; const string str = "RGW"; priority_queue<array<int, 4>, vector<array<int, 4>>, greater<array<int, 4>>> q; int n, m; bool check_ok(int i, int j, int p) { if (i < 0 || j < 0 || i >= n || j >= m) return false; string curr; if (p == 0) { for(int k = 0; k < 3; k++) { curr += mat[i][j+k]; } } else { for(int k = 0; k < 3; k++) { curr += mat[i+k][j]; } } return (curr == str); } int thru(int i, int j, int p) { int cnt = 0; if (p == 0) { for(int k = 0; k < 3; k++) { cnt += check_ok(i-k, j+k, 1); } } else { for(int k = 0; k < 3; k++) { cnt += check_ok(i+k, j-k, 0); } } return cnt; } void rem(int i, int j, int p) { if (p == 0) { for(int k = 0; k < 3; k++) { mat[i][j+k] = 'X'; } } else { for(int k = 0; k < 3; k++) { mat[i+k][j] = 'X'; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin >> mat[i][j]; } } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if (check_ok(i, j, 0)) { int cnt = thru(i, j, 0); // cout << i << " " << j << " 0 " << cnt << "\n"; q.push({cnt, i, j, 0}); } if (check_ok(i, j, 1)) { int cnt = thru(i, j, 1); // cout << i << " " << j << " 1 " << cnt << "\n"; q.push({cnt, i, j, 1}); } } } int ans = 0; while(!q.empty()) { auto v = q.top(); q.pop(); int x = v[1], y = v[2], p = v[3]; if (!check_ok(x, y, p)) continue; ans++; rem(x, y, p); for(int i = max(0, x-3); i < min(n, x+3); i++) { for(int j = max(0, y-3); j < min(m, y+3); j++) { if (check_ok(i, j, 0)) { int cnt = thru(i, j, 0); q.push({cnt, i, j, 0}); } if (check_ok(i, j, 1)) { int cnt = thru(i, j, 1); q.push({cnt, i, j, 1}); } } } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...