Submission #399430

#TimeUsernameProblemLanguageResultExecution timeMemory
399430SavicSDango Maker (JOI18_dango_maker)C++14
100 / 100
314 ms35720 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ff(i,a,b) for(int i=a;i<=b;i++) #define fb(i,b,a) for(int i=b;i>=a;i--) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; const int maxn = 3005; const int inf = 1e9 + 5; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) int n, m; char mat[maxn][maxn]; bool ok[maxn][maxn][2]; int dp[maxn][3]; int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n >> m; ff(i,1,n)ff(j,1,m)cin >> mat[i][j]; ff(i,1,n) { ff(j,1,m) { if(mat[i][j] == 'G') { if(i > 1 && i < n && mat[i - 1][j] == 'R' && mat[i + 1][j] == 'W')ok[i][j][0] = 1; if(j > 1 && j < m && mat[i][j - 1] == 'R' && mat[i][j + 1] == 'W')ok[i][j][1] = 1; } } } int rez = 0; ff(a,1,n + m) { memset(dp, 0, sizeof(dp)); ff(i,1,n) { if(a - i >= 1 && a - i <= m) { int j = a - i; dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}); if(ok[i][j][0])dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1; if(ok[i][j][1])dp[i][2] = max(dp[i - 1][0], dp[i - 1][2]) + 1; } else ff(j,0,2)dp[i][j] = dp[i - 1][j]; } rez += max({dp[n][0], dp[n][1], dp[n][2]}); } cout << rez << endl; return 0; } /** 3 4 RGWR GRGG RGWW // probati bojenje sahovski ili slicno **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...