제출 #902227

#제출 시각아이디문제언어결과실행 시간메모리
902227KienTranDango Maker (JOI18_dango_maker)C++14
33 / 100
5 ms9824 KiB
#include <bits/stdc++.h> #define ii pair <int, int> #define fi first.first #define se first.second #define th second using namespace std; const int O = 3e2 + 5; const int base = 500; const int mod = 998244353; int n, m, cnt, cal, c[O][O], dd[2][O][O]; string a[O]; vector <pair <ii, int>> g[2][O][O]; int dfs(pair <ii, int> u){ vector <int> f[2], b; queue <pair <ii, int>> q; q.push(u); int turn = u.fi; dd[u.fi][u.se][u.th] = 1; cal = 0; while (q.size()){ u = q.front(); q.pop(); //cout << u.fi << " " << u.se << " " << u.th << endl; if (turn != u.fi) b.push_back(cal); cal = turn == u.fi ? cal + 1 : 1; turn = u.fi; for (auto v : g[u.fi][u.se][u.th]){ if (!dd[v.fi][v.se][v.th]){ dd[v.fi][v.se][v.th] = 1; q.push(v); } } } b.push_back(cal); int m = b.size() - 1; f[0].resize(m + 1); f[1].resize(m + 1); f[1][0] = b[0]; for (int i = 1; i <= m; ++ i){ f[1][i] = f[0][i - 1] + b[i]; f[0][i] = max(f[0][i - 1], f[1][i - 1]); } return max(f[0][m], f[1][m]); } main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++ i){ cin >> a[i]; a[i] = " " + a[i]; for (int j = 1; j <= m; ++ j){ if (a[i][j] == 'W' && j >= 3){ c[i][j - 2] += (a[i][j - 2] == 'R' && a[i][j - 1] == 'G'); } if (a[i][j] == 'W' && i >= 3){ c[i - 2][j] += 2 * (a[i - 2][j] == 'R' && a[i - 1][j] == 'G'); } } } for (int i = 1; i <= n; ++ i){ for (int j = 1; j <= m - 2; ++ j){ if (c[i][j] & 1){ if (i > 2 && (c[i - 2][j + 2] & 2)){ g[0][i][j].push_back(make_pair(make_pair(1, i - 2), j + 2)); g[1][i - 2][j + 2].push_back(make_pair(make_pair(0, i), j)); } if (i > 1 && (c[i - 1][j + 1] & 2)){ g[0][i][j].push_back(make_pair(make_pair(1, i - 1), j + 1)); g[1][i - 1][j + 1].push_back(make_pair(make_pair(0, i), j)); } if (c[i][j] & 2){ g[0][i][j].push_back(make_pair(make_pair(1, i), j)); g[1][i][j].push_back(make_pair(make_pair(0, i), j)); } } } } int res = 0; for (int i = 1; i <= n; ++ i){ for (int j = 1; j <= m; ++ j){ if (c[i][j] > 0){ cnt = cal = 0; //cout << "debug " << i << " " << j << endl; if ((c[i][j] & 1) && !dd[0][i][j]){ cnt = dfs(make_pair(make_pair(0, i), j)); } if ((c[i][j] & 2) && !dd[1][i][j]){ cnt = dfs(make_pair(make_pair(1, i), j)); } //cout << cnt << " " << cal << endl; //cout << "end" << endl; res += cnt; } } } cout << res; } /*** 5 5 RGWRR GRRGW WRGWR RGWRG XWRGW ***/

컴파일 시 표준 에러 (stderr) 메시지

dango_maker.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   57 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...