Submission #530632

#TimeUsernameProblemLanguageResultExecution timeMemory
530632kevinDango Maker (JOI18_dango_maker)C++17
0 / 100
5 ms7372 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[300001]; bool vis[3000001]; int dp[3000001][2]; 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; for(int a=0; a<n; a++){ for(int b=m-1; b>=0; b--){ int i = 0; if(onh[a][b]) i = onh[a][b]; else if(onv[a][b] && (i == 0 || adj[onv[a][b]].size() < adj[i].size())) i = onv[a][b]; if(i){ vis[i] = 1; queue<int> q; q.push(i); while(q.size()){ int c = q.front(); q.pop(); dp[c][0] = 1; for(int a:adj[c]){ if(!vis[a]){ q.push(a); vis[a] = 1; } else{ dp[a][0] += dp[c][1]; dp[a][1] += max(dp[c][1], dp[c][0]); } } if(q.size() == 0){ ans += max(dp[c][0], dp[c][1]); } } } } } cout<<ans; }

Compilation message (stderr)

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:22:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     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...