Submission #562940

#TimeUsernameProblemLanguageResultExecution timeMemory
562940dattranxxxDango Maker (JOI18_dango_maker)C++11
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; void file() { const string FILE_NAME = "FILE_NAME"; freopen((FILE_NAME + ".inp").c_str(), "r", stdin); freopen((FILE_NAME + ".out").c_str(), "w", stdout); } const int N = 10; string s[N]; int n, m, d = 0; int pos[N][N][4]; // left down right up #define LEFT 0 #define DOWN 1 #define RIGHT 2 #define UP 3 int tag(int i, int j, int dir) { if (i < 0 || j < 0 || i >= n || j >= m) return 0; return pos[i][j][dir]; } vector<int> G[N * N * 4 + 5]; bitset<N * N * 4 + 5> vis; int c[2]; void dfs(int u, int col = 0) { vis[u] = 1, c[col]++; for (int v : G[u]) if (!vis[v]) dfs(v, !col); } int main() { cin.tie(0)->sync_with_stdio(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; ++i) cin >> s[i]; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { if (j <= m-3 && s[i][j] == 'R' && s[i][j+1] == 'G' && s[i][j+2] == 'W') pos[i][j][LEFT] = ++d; if (i <= n-3 && s[i][j] == 'R' && s[i+1][j] == 'G' && s[i+2][j] == 'W') pos[i][j][DOWN] = ++d; if (j >= 2 && s[i][j] == 'R' && s[i][j-1] == 'G' && s[i][j-2] == 'W') pos[i][j][RIGHT] = ++d; if (i >= 2 && s[i][j] == 'R' && s[i-1][j] == 'G' && s[i-2][j] == 'W') pos[i][j][UP] = ++d; } for (int i = 0, u, v; i < n; ++i) for (int j = 0; j < m; ++j) { if (u = pos[i][j][LEFT]) { if (v = pos[i][j][DOWN]) G[u].emplace_back(v); if (v = pos[i][j][RIGHT]) G[u].emplace_back(v); if (v = pos[i][j][UP]) G[u].emplace_back(v); if (v = tag(i-1, j+1, DOWN)) G[u].emplace_back(v); if (v = tag(i+1, j+1, UP)) G[u].emplace_back(v); if (v = tag(i-2, j+2, DOWN)) G[u].emplace_back(v); if (v = tag(i+2, j+2, UP)) G[u].emplace_back(v); if (v = tag(i, j+4, RIGHT)) G[u].emplace_back(v); } if (u = pos[i][j][DOWN]) { if (v = pos[i][j][LEFT]) G[u].emplace_back(v); if (v = pos[i][j][RIGHT]) G[u].emplace_back(v); if (v = pos[i][j][UP]) G[u].emplace_back(v); if (v = tag(i+1, j-1, RIGHT)) G[u].emplace_back(v); if (v = tag(i+1, j+1, LEFT)) G[u].emplace_back(v); if (v = tag(i+2, j-2, RIGHT)) G[u].emplace_back(v); if (v = tag(i+2, j+2, LEFT)) G[u].emplace_back(v); if (v = tag(i+4, j, UP)) G[u].emplace_back(v); } if (u = pos[i][j][RIGHT]) { if (v = pos[i][j][DOWN]) G[u].emplace_back(v); if (v = pos[i][j][LEFT]) G[u].emplace_back(v); if (v = pos[i][j][UP]) G[u].emplace_back(v); if (v = tag(i-1, j-1, DOWN)) G[u].emplace_back(v); if (v = tag(i+1, j-1, UP)) G[u].emplace_back(v); if (v = tag(i-2, j-2, DOWN)) G[u].emplace_back(v); if (v = tag(i+2, j-2, UP)) G[u].emplace_back(v); if (v = tag(i, j-4, LEFT)) G[u].emplace_back(v); } if (u = pos[i][j][UP]) { if (v = pos[i][j][LEFT]) G[u].emplace_back(v); if (v = pos[i][j][RIGHT]) G[u].emplace_back(v); if (v = pos[i][j][DOWN]) G[u].emplace_back(v); if (v = tag(i-1, j-1, RIGHT)) G[u].emplace_back(v); if (v = tag(i-1, j+1, LEFT)) G[u].emplace_back(v); if (v = tag(i-2, j-2, RIGHT)) G[u].emplace_back(v); if (v = tag(i-2, j+2, LEFT)) G[u].emplace_back(v); if (v = tag(i-4, j, DOWN)) G[u].emplace_back(v); } } int res = 0; for (int i = 1; i <= d; ++i) if (!vis[i]) { c[0] = 0, c[1] = 0, dfs(i); res += max(c[0], c[1]); } cout << res; return 0; }

Compilation message (stderr)

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:41:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   41 |   if (u = pos[i][j][LEFT]) {
      |       ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:42:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   42 |    if (v = pos[i][j][DOWN]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:43:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   43 |    if (v = pos[i][j][RIGHT]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~
dango_maker.cpp:44:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   44 |    if (v = pos[i][j][UP]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~
dango_maker.cpp:46:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   46 |    if (v = tag(i-1, j+1, DOWN)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:47:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   47 |    if (v = tag(i+1, j+1, UP)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~
dango_maker.cpp:48:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   48 |    if (v = tag(i-2, j+2, DOWN)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:49:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   49 |    if (v = tag(i+2, j+2, UP)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~
dango_maker.cpp:50:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   50 |    if (v = tag(i, j+4, RIGHT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:52:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   52 |   if (u = pos[i][j][DOWN]) {
      |       ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:53:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   53 |    if (v = pos[i][j][LEFT]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:54:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   54 |    if (v = pos[i][j][RIGHT]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~
dango_maker.cpp:55:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   55 |    if (v = pos[i][j][UP]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~
dango_maker.cpp:57:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   57 |    if (v = tag(i+1, j-1, RIGHT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:58:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   58 |    if (v = tag(i+1, j+1, LEFT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:59:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   59 |    if (v = tag(i+2, j-2, RIGHT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:60:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   60 |    if (v = tag(i+2, j+2, LEFT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:61:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   61 |    if (v = tag(i+4, j, UP)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:63:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   63 |   if (u = pos[i][j][RIGHT]) {
      |       ~~^~~~~~~~~~~~~~~~~~
dango_maker.cpp:64:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   64 |    if (v = pos[i][j][DOWN]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:65:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   65 |    if (v = pos[i][j][LEFT]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:66:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   66 |    if (v = pos[i][j][UP]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~
dango_maker.cpp:68:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   68 |    if (v = tag(i-1, j-1, DOWN)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:69:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   69 |    if (v = tag(i+1, j-1, UP)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~
dango_maker.cpp:70:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   70 |    if (v = tag(i-2, j-2, DOWN)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:71:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   71 |    if (v = tag(i+2, j-2, UP)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~
dango_maker.cpp:72:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   72 |    if (v = tag(i, j-4, LEFT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~
dango_maker.cpp:74:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   74 |   if (u = pos[i][j][UP]) {
      |       ~~^~~~~~~~~~~~~~~
dango_maker.cpp:75:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   75 |    if (v = pos[i][j][LEFT]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:76:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   76 |    if (v = pos[i][j][RIGHT]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~
dango_maker.cpp:77:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   77 |    if (v = pos[i][j][DOWN]) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:79:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   79 |    if (v = tag(i-1, j-1, RIGHT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:80:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   80 |    if (v = tag(i-1, j+1, LEFT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:81:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   81 |    if (v = tag(i-2, j-2, RIGHT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:82:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   82 |    if (v = tag(i-2, j+2, LEFT)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:83:10: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   83 |    if (v = tag(i-4, j, DOWN)) G[u].emplace_back(v);
      |        ~~^~~~~~~~~~~~~~~~~~~
dango_maker.cpp: In function 'void file()':
dango_maker.cpp:6:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |  freopen((FILE_NAME + ".inp").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:7:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  freopen((FILE_NAME + ".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...