Submission #79781

#TimeUsernameProblemLanguageResultExecution timeMemory
79781antimirageDango Maker (JOI18_dango_maker)C++17
13 / 100
72 ms71352 KiB
#include <bits/stdc++.h> #define pb emplace_back using namespace std; const int N = 3005; int n, m, d[2][N][N], sz, u[3000005], wh, bl, ans, used[3000005], dp[3000005][2]; char ar[N][N]; vector <int> g[3000005], vec; void dfs1 (int v, int color) { if (color == 0) wh++; else bl++; u[v] = 1; for (auto to : g[v]) { if (!u[to]) dfs1(to, color ^ 1); } } bool fl; void check(int v, int p) { vec.push_back(v); used[v] = 1; for (auto to : g[v]) { if (to == p) continue; if (used[to]) fl = false; else check(to, v); } } void dfs2 (int v, int p) { u[v] = 1; int sum1 = 1, sum2 = 0; for (auto to : g[v]) { if (to == p) continue; dfs2(to, v); sum1 += dp[to][0]; sum2 += max(dp[to][0], dp[to][1]); } dp[v][0] = sum2; dp[v][1] = sum1; } main() { cin >> n >> m; for (int i = 1; i <= n; i++) { scanf("\n"); for (int j = 1; j <= m; j++) scanf("%c", &ar[i][j]); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if ( j + 2 <= m && ar[i][j] == 'R' && ar[i][j + 1] == 'G' && ar[i][j + 2] == 'W' ) d[0][i][j] = ++sz; if ( i + 2 <= n && ar[i][j] == 'R' && ar[i + 1][j] == 'G' && ar[i + 2][j] == 'W') d[1][i][j] = ++sz; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if ( d[0][i][j] ) { if (d[1][i][j]) g[ d[0][i][j] ].pb( d[1][i][j] ); if (d[1][i - 1][j + 1]) g[ d[0][i][j] ].pb( d[1][i - 1][j + 1] ); if (d[1][i - 2][j + 2]) g[ d[0][i][j] ].pb( d[1][i - 2][j + 2] ); } if ( d[1][i][j] ) { if (d[0][i][j]) g[ d[1][i][j] ].pb( d[0][i][j] ); if (d[0][i + 1][j - 1]) g[ d[1][i][j] ].pb( d[0][i + 1][j - 1] ); if (d[0][i + 2][j - 2]) g[ d[1][i][j] ].pb( d[0][i + 2][j - 2] ); } } } for (int i = 1; i <= sz; i++) { if (u[i]) continue; vec.clear(); fl = 1; check(i, 0); if (fl) { dfs2(i, 0); ans += max(dp[i][0], dp[i][1]); } else { wh = bl = 0; dfs1(i, 0); ans += max( wh, bl ); } for (auto to : vec) used[to] = dp[to][0] = dp[to][1] = 0; } cout << ans << endl; } /** 7 7 RRRRRGW RRRRGWR RRRGWRR RRGRRRR RGWRRRR GWRRRRR WRRRRRR **/

Compilation message (stderr)

dango_maker.cpp:61:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("\n");
         ~~~~~^~~~~~
dango_maker.cpp:69:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%c", &ar[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...