Submission #530618

#TimeUsernameProblemLanguageResultExecution timeMemory
530618kevinDango Maker (JOI18_dango_maker)C++17
13 / 100
124 ms211984 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define nl cout<<"\n" #define all(x) x.begin(), x.end() #define f first #define s second #define ca(v) for(auto i:v) cout<<i<<" "; const int MOD = 1e9 + 7; int onv[3001][3001]; int onh[3001][3001]; list<int> adj[3001*3001]; bool vis[3001*3001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("input.in", "r")) freopen("input.in", "r", stdin); int n, m; cin>>n>>m; char grid[n][m]; for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ cin>>grid[i][j]; } } int cnt = 0; for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if(grid[i][j] == 'R' && j+2 < m && grid[i][j+1] == 'G' && grid[i][j+2] == 'W') onh[i][j] = ++cnt; } } for(int j=0; j<m; j++){ for(int i=0; i<n; i++){ if(grid[i][j] == 'R' && i+2 < n && grid[i+1][j] == 'G' && grid[i+2][j] == 'W') onv[i][j] = ++cnt; } } for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if(onh[i][j]){ for(int k=0; k<3; k++){ if(i-k >= 0 && j+k < m && onv[i-k][j+k]){ adj[onh[i][j]].push_back(onv[i-k][j+k]); adj[onv[i-k][j+k]].push_back(onh[i][j]); } } } } } int ans = 0; vector<int> label(cnt+1, 0); for(int i=1; i<=cnt; i++){ if(!vis[i]){ vis[i] = 1; int cn[2] = {0, 0}; queue<pair<int, int>> q; q.push({i, 0}); while(q.size()){ auto c = q.front(); cn[c.s]++; q.pop(); for(int a:adj[c.f]){ if(!vis[a]){ label[a] = 1-c.s; q.push({a, 1-c.s}); vis[a] = 1; } else assert(label[a] == 1-c.s); } } ans += max(cn[0], cn[1]); } } cout<<ans; }

Compilation message (stderr)

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:21:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
      |                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...