Submission #467457

#TimeUsernameProblemLanguageResultExecution timeMemory
467457Killer2501Dango Maker (JOI18_dango_maker)C++14
100 / 100
523 ms216668 KiB
#include <bits/stdc++.h>
#define ll int
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second

using namespace std;
const ll mod = 1e15;
const ll N = 3e3+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, dp[N*2][3], a[N][N][3];
char c[N][N];
vector<pll> adj[N*2];
vector<ll> kq;
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)cin >> c[i][j];
    }
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)
        {
            if(i > 1 && i < n)a[i][j][1] = (c[i-1][j] == 'R' && c[i][j] == 'G' && c[i+1][j] == 'W');
            if(j > 1 && j < m)a[i][j][2] = (c[i][j-1] == 'R' && c[i][j] == 'G' && c[i][j+1] == 'W');
            adj[i+j].pb({i, j});
            //if(a[i][j][1])cout << i <<" "<<j<<" "<<1<<'\n';
            //if(a[i][j][2])cout << i <<" "<<j<<" "<<2<<'\n';
        }
    }
    for(int i = 2; i <= m+n; i ++)
    {
        k = adj[i].size();
        for(int j = 1; j <= k; j ++)
        {
            ll x = adj[i][j-1].fi, y = adj[i][j-1].se;
            dp[j][0] = max(dp[j-1][0], max(dp[j-1][1], dp[j-1][2]));
            for(int p = 1; p <= 2; p ++)
            {
                if(a[x][y][p])dp[j][p] = max(dp[j-1][p], dp[j-1][0]) + 1;
                else dp[j][p] = 0;
            }
        }
        ans += max(dp[k][0], max(dp[k][1], dp[k][2]));
        //cout << max(dp[k][0], max(dp[k][1], dp[k][2])) <<" ";
    }
    cout << ans;
}
int main()
{
    if(fopen(task".in", "r"))
    {
       freopen(task".in", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
4 5 2
10 9 5 2
6 4 20 15
9 7 10 9
-1 -1 16 11
1 2 3
2 3 3
1 4 1
4 3 1
3 1 1

*/

Compilation message (stderr)

dango_maker.cpp:11:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+15' to '2147483647' [-Woverflow]
   11 | const ll mod = 1e15;
      |                ^~~~
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:68:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:69:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...