Submission #1276551

#TimeUsernameProblemLanguageResultExecution timeMemory
1276551tm.khoa.tmDango Maker (JOI18_dango_maker)C++20
0 / 100
91 ms212340 KiB
//I love ManchesterUnited #include<bits/stdc++.h> using namespace std; #define love ManchesterUnited #define int long long #define pb push_back #define FOR(i,a,b) for (int i=(a); i<=(b); i++) #define FORD(i,b,a) for (int i=(b); i>=(a); i--) #define REP(i, n) for(int i=0; i<(n); ++i) #define RED(i, n) for(int i=(n)-1; i>=0; --i) #define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms."; #define ALL(a) (a).begin(),(a).end() #define cout cerr #define ii pair<int,int> #define iii pair<int,ii> #define fi first #define se second #define endl '\n' #define MASK(x) (1 << (x)) #define BIT(mask,i) ((mask >> i) & 1) typedef long long ll; template<class X, class Y> bool minimize(X &x, const Y &y) { if (x > y) { x = y; return true; } else return false; } template<class X, class Y> bool maximize(X &x, const Y &y) { if (x < y) { x = y; return true; } else return false; } template<class T> T Abs(const T &x) { return (x < 0 ? -x : x); } //___________________________________________________________________________________________________________________________________________________________ // CODE: const int N = 3005; const int MOD = 1e9 + 7; const int INF = 1e18; int n,m; char a[N][N]; int dp[N][N][3]; bool can(int i,int j,int c){ if (i >= 1 && j >= 1 && i <= n && j <= m && a[i][j] == c) return true; return false; } int f(int x,int y,int type){ if (x > n || y > m || x < 1 || y < 1) return 0; int &res = dp[x][y][type]; if (res != -1) return res; int add = 0; if (type == 1 && can(x - 2,y,'R') && can(x - 1,y,'G') && can(x,y,'W')) add = 1; if (type == 2 && can(x,y - 2,'R') && can(x,y - 2,'G') && can(x,y,'W')) add = 1; if (type != 0 && add == 0) return 0; res = 0; REP(i,3){ if (type + i == 3) continue; res = max(res,f(x - 1,y + 1,i) + add); } return res; } int32_t main() { // freopen("test.inp","r",stdin); // freopen("test.out","w",stdout); ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; memset(dp,-1,sizeof dp); FOR(i,1,n) FOR(j,1,m) cin >> a[i][j]; int ans = 0; FOR(i,1,n) ans += max({f(i,1,0), f(i,1,1), f(i,1,2)}); FOR(i,2,m) ans += max({f(n,i,0), f(n,i,1), f(n,i,2)}); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...