Submission #77363

# Submission time Handle Problem Language Result Execution time Memory
77363 2018-09-26T10:50:34 Z Charis02 Dango Maker (JOI18_dango_maker) C++14
100 / 100
398 ms 113476 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 3004
#define INF 1e9+7

using namespace std;

ll n,m,ans;
char ar[N][N];
ll dp[N][3]; // dp[.][1] = chose up in last row

bool can(pi r,pi g,pi w)
{
    if(w.first < 0 || w.first >= n || w.second < 0 || w.second >= m)
        return false;

    return (ar[r.first][r.second] == 'R' && ar[g.first][g.second] == 'G' && ar[w.first][w.second] == 'W');
}

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> m;

    rep(i,0,n)
    {
        rep(j,0,m)
        {
            cin >> ar[i][j];
        }
    }

    rep(s,0,n+m-1)
    {
        memset(dp,0,sizeof dp);

        ll j = min(m-1,(ll)s);
        ll i = s - j;

        dp[i][0] = 0;

        if(can(mp(i-1,j),mp(i,j),mp(i+1,j)))
        {
            dp[i][1] = 1;
        }

        if(can(mp(i,j-1),mp(i,j),mp(i,j+1)))
        {
            dp[i][2] = 1;
        }

        i++;
        j--;

        while(i <= s && j >= 0)
        {
            dp[i][0] = max(dp[i-1][1],dp[i-1][2]);
            dp[i][1] = max(dp[i-1][0],dp[i-1][1]) + (ll)(can(mp(i-1,j),mp(i,j),mp(i+1,j)));
            dp[i][2] = max(dp[i-1][0],dp[i-1][2]) + (ll)(can(mp(i,j-1),mp(i,j),mp(i,j+1)));

            i++;
            j--;
        }

        i--;
        j++;

        ans += max(dp[i][0],max(dp[i][1],dp[i][2]));
    }

    cout << ans << endl;

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 732 KB Output is correct
11 Correct 2 ms 732 KB Output is correct
12 Correct 3 ms 732 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 732 KB Output is correct
11 Correct 2 ms 732 KB Output is correct
12 Correct 3 ms 732 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 2 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 2 ms 764 KB Output is correct
20 Correct 2 ms 764 KB Output is correct
21 Correct 2 ms 764 KB Output is correct
22 Correct 2 ms 764 KB Output is correct
23 Correct 2 ms 764 KB Output is correct
24 Correct 2 ms 776 KB Output is correct
25 Correct 2 ms 792 KB Output is correct
26 Correct 3 ms 792 KB Output is correct
27 Correct 2 ms 792 KB Output is correct
28 Correct 2 ms 792 KB Output is correct
29 Correct 2 ms 792 KB Output is correct
30 Correct 2 ms 792 KB Output is correct
31 Correct 2 ms 792 KB Output is correct
32 Correct 3 ms 796 KB Output is correct
33 Correct 3 ms 800 KB Output is correct
34 Correct 2 ms 804 KB Output is correct
35 Correct 2 ms 936 KB Output is correct
36 Correct 2 ms 956 KB Output is correct
37 Correct 3 ms 988 KB Output is correct
38 Correct 2 ms 988 KB Output is correct
39 Correct 2 ms 988 KB Output is correct
40 Correct 2 ms 988 KB Output is correct
41 Correct 2 ms 988 KB Output is correct
42 Correct 3 ms 988 KB Output is correct
43 Correct 3 ms 988 KB Output is correct
44 Correct 3 ms 988 KB Output is correct
45 Correct 2 ms 988 KB Output is correct
46 Correct 2 ms 988 KB Output is correct
47 Correct 2 ms 988 KB Output is correct
48 Correct 3 ms 988 KB Output is correct
49 Correct 2 ms 988 KB Output is correct
50 Correct 2 ms 988 KB Output is correct
51 Correct 2 ms 988 KB Output is correct
52 Correct 2 ms 988 KB Output is correct
53 Correct 2 ms 988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 732 KB Output is correct
11 Correct 2 ms 732 KB Output is correct
12 Correct 3 ms 732 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 2 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 2 ms 764 KB Output is correct
20 Correct 2 ms 764 KB Output is correct
21 Correct 2 ms 764 KB Output is correct
22 Correct 2 ms 764 KB Output is correct
23 Correct 2 ms 764 KB Output is correct
24 Correct 2 ms 776 KB Output is correct
25 Correct 2 ms 792 KB Output is correct
26 Correct 3 ms 792 KB Output is correct
27 Correct 2 ms 792 KB Output is correct
28 Correct 2 ms 792 KB Output is correct
29 Correct 2 ms 792 KB Output is correct
30 Correct 2 ms 792 KB Output is correct
31 Correct 2 ms 792 KB Output is correct
32 Correct 3 ms 796 KB Output is correct
33 Correct 3 ms 800 KB Output is correct
34 Correct 2 ms 804 KB Output is correct
35 Correct 2 ms 936 KB Output is correct
36 Correct 2 ms 956 KB Output is correct
37 Correct 3 ms 988 KB Output is correct
38 Correct 2 ms 988 KB Output is correct
39 Correct 2 ms 988 KB Output is correct
40 Correct 2 ms 988 KB Output is correct
41 Correct 2 ms 988 KB Output is correct
42 Correct 3 ms 988 KB Output is correct
43 Correct 3 ms 988 KB Output is correct
44 Correct 3 ms 988 KB Output is correct
45 Correct 2 ms 988 KB Output is correct
46 Correct 2 ms 988 KB Output is correct
47 Correct 2 ms 988 KB Output is correct
48 Correct 3 ms 988 KB Output is correct
49 Correct 2 ms 988 KB Output is correct
50 Correct 2 ms 988 KB Output is correct
51 Correct 2 ms 988 KB Output is correct
52 Correct 2 ms 988 KB Output is correct
53 Correct 2 ms 988 KB Output is correct
54 Correct 31 ms 988 KB Output is correct
55 Correct 19 ms 9856 KB Output is correct
56 Correct 31 ms 9856 KB Output is correct
57 Correct 14 ms 9856 KB Output is correct
58 Correct 46 ms 9856 KB Output is correct
59 Correct 374 ms 19644 KB Output is correct
60 Correct 388 ms 28500 KB Output is correct
61 Correct 398 ms 37440 KB Output is correct
62 Correct 28 ms 37440 KB Output is correct
63 Correct 388 ms 46004 KB Output is correct
64 Correct 302 ms 54712 KB Output is correct
65 Correct 312 ms 63496 KB Output is correct
66 Correct 287 ms 72416 KB Output is correct
67 Correct 332 ms 81304 KB Output is correct
68 Correct 307 ms 89992 KB Output is correct
69 Correct 304 ms 98900 KB Output is correct
70 Correct 37 ms 98900 KB Output is correct
71 Correct 36 ms 98900 KB Output is correct
72 Correct 36 ms 98900 KB Output is correct
73 Correct 40 ms 98900 KB Output is correct
74 Correct 53 ms 98900 KB Output is correct
75 Correct 36 ms 98900 KB Output is correct
76 Correct 38 ms 99784 KB Output is correct
77 Correct 37 ms 100848 KB Output is correct
78 Correct 37 ms 101872 KB Output is correct
79 Correct 37 ms 102728 KB Output is correct
80 Correct 37 ms 103708 KB Output is correct
81 Correct 38 ms 104692 KB Output is correct
82 Correct 38 ms 105668 KB Output is correct
83 Correct 37 ms 106648 KB Output is correct
84 Correct 38 ms 107644 KB Output is correct
85 Correct 37 ms 108624 KB Output is correct
86 Correct 50 ms 109604 KB Output is correct
87 Correct 37 ms 110600 KB Output is correct
88 Correct 38 ms 111596 KB Output is correct
89 Correct 37 ms 112580 KB Output is correct
90 Correct 54 ms 113476 KB Output is correct