제출 #531815

#제출 시각아이디문제언어결과실행 시간메모리
531815zxcvbnmDango Maker (JOI18_dango_maker)C++14
33 / 100
1 ms460 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int nax = 105; char mat[nax][nax]; const string str = "RGW"; /* 0 - desine 1 - virsus */ bool gali[nax][nax][2]; int n, m; int dp[nax][3]; bool check_ok(int i, int j, int p) { if (i < 0 || j < 0 || i >= n || j >= m) return false; string curr; if (p == 0) { for(int k = 0; k < 3; k++) { curr += mat[i][j+k]; } } else { for(int k = 0; k < 3; k++) { curr += mat[i+k][j]; } } return (curr == str); } bool in(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin >> mat[i][j]; } } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if (mat[i][j] == 'G') { if (j-1 >= 0) { gali[i][j][0] = check_ok(i, j-1, 0); } if (i-1 >= 0) { gali[i][j][1] = check_ok(i-1, j, 1); } } } } vector<pair<int, int>> s[nax+nax]; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { s[i+j].push_back({i, j}); } } int ans = 0; for(int sz = 0; sz < m+n; sz++) { for(const auto& p : s[sz]) { int i = p.first, j = p.second; // cout << "curr: " << i << " " << j << "\n"; if (i) { dp[i][0] = max({dp[i-1][0], dp[i-1][1], dp[i-1][2]}); if (gali[i][j][0]) { dp[i][1] = max(dp[i-1][0], dp[i-1][1]) + 1; } if (gali[i][j][1]) { dp[i][2] = max(dp[i-1][0], dp[i-1][2]) + 1; } } else { if (gali[i][j][0]) { dp[i][1] = ans+1; } if (gali[i][j][1]) { dp[i][2] = ans+1; } } // cout << i << " " << j << ":\n"; for(int k = 0; k < 3; k++) { ans = max(ans, dp[i][k]); // cout << dp[i][k] << " "; } // cout << "\n"; } for(int i = 0; i < n; i++) { dp[i][0] = ans; } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...