This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// g++ -std=c++14
/*
Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.
- Tooru Oikawa.
*/
#include<bits/stdc++.h>
typedef long long ll;
typedef long double lld;
using namespace std;
#define endl "\n"
#define fi first
#define se second
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r)
{
uniform_int_distribution<int> uid(l, r);
return uid(rng);
}
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
for (auto i = v.begin(); i != v.end(); i++)
out << (*i) << ' ';
return out;
}
template <typename T>
ostream &operator<<(ostream &out, multiset<T> const &v) {
for (auto i = v.begin(); i != v.end(); i++)
out << (*i) << ' ';
return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
for (auto i = v.begin(); i != v.end(); i++)
out << "\n" << (i->first) << ":" << (i->second);
return out;
}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
#define int ll
const int N = 3004;
string arr[N];
int dp[N][N];
int n, m;
string s = "RGW";
int f(int r, int c) {
if (r >= n || c >= m) return 0;
int &ans = dp[r][c];
if (ans != -1) return ans;
ans = 0;
int done = 0;
for (int i = r; i < r + 3; i++) {
if (i >= n || arr[i][c] != s[i - r]) {
done = 1;
break;
}
}
if (done == 0) {
ans = 1 + f(r + 3, c) + f(r, c + 1) - f(r + 3, c + 1);
}
done = 0;
for (int i = c; i < c + 3; i++) {
if (i >= m || arr[r][i] != s[i - c]) {
done = 1;
break;
}
}
if (done == 0) {
ans = max(ans, 1 + f(r, c + 3) + f(r + 1, c) - f(r + 1, c + 3));
}
ans = max(ans, f(r + 1, c) + f(r, c + 1) - f(r + 1, c + 1));
return ans;
}
int solve() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
MEMS(dp, -1);
cout << f(0, 0) << endl;
return 0;
}
int32_t main(){ _
int t;
// cin >> t;
t = 1;
while (t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |