Submission #868619

#TimeUsernameProblemLanguageResultExecution timeMemory
868619mgl_diamondDango Maker (JOI18_dango_maker)C++17
100 / 100
165 ms53496 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; #define foru(i, l, r) for(int i=(l); i<=(r); ++i) #define ford(i, l, r) for(int i=(l); i>=(r); --i) #define fore(x, v) for(auto &x : v) #define all(x) (x).begin(), (x).end() #define sz(x) (int)x.size() void setIO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("input.in", "r")) { freopen("input.in", "r", stdin); freopen("input.out", "w", stdout); } } const int N = 3003; int n, m, proc[N][N]; char mat[N][N]; int ans = 0; int dp[2][3]; bool can(int t, int i, int j) { if (t == 1) return mat[i][j-1] == 'R' && mat[i][j+1] == 'W'; return mat[i-1][j] == 'R' && mat[i+1][j] == 'W'; } int main() { setIO(); cin >> n >> m; foru(i, 1, n) foru(j, 1, m) cin >> mat[i][j]; foru(i, 1, n) foru(j, 1, m) if (mat[i][j] == 'G' && !proc[i][j]) { int u = i, v = j; int cur = 0, prv = 1; dp[prv][0] = dp[prv][1] = dp[prv][2] = 0; while (u <= n && v >= 1) { if (mat[u][v] != 'G') break; proc[u][v] = 1; memset(dp[cur], 0, sizeof(dp[cur])); dp[cur][0] = max({dp[prv][0], dp[prv][1], dp[prv][2]}); if (can(1, u, v)) dp[cur][1] = max(dp[prv][0], dp[prv][1]) + 1; if (can(2, u, v)) dp[cur][2] = max(dp[prv][0], dp[prv][2]) + 1; cur ^= 1; prv ^= 1; ++u; --v; } // cout << i << " " << j << " " << max({dp[prv][0], dp[prv][1], dp[prv][2]}); ans += max({dp[prv][0], dp[prv][1], dp[prv][2]}); } cout << ans; }

Compilation message (stderr)

dango_maker.cpp: In function 'void setIO()':
dango_maker.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen("input.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...