Submission #531817

# Submission time Handle Problem Language Result Execution time Memory
531817 2022-03-01T15:25:39 Z zxcvbnm Dango Maker (JOI18_dango_maker) C++14
100 / 100
562 ms 128320 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr int nax = 3005;
char mat[nax][nax];
const string str = "RGW";

/*
    0 - desine
    1 - virsus
*/

bool gali[nax][nax][2];
int n, m;
int dp[nax][3];

bool check_ok(int i, int j, int p) {
    if (i < 0 || j < 0 || i >= n || j >= m) return false;

    string curr;
    if (p == 0) {
        for(int k = 0; k < 3; k++) {
            curr += mat[i][j+k];
        }
    }
    else {
        for(int k = 0; k < 3; k++) {
            curr += mat[i+k][j];
        }
    }
    return (curr == str);
}

bool in(int x, int y) {
    return x >= 0 && x < n && y >= 0 && y < m;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> mat[i][j];
        }
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (mat[i][j] == 'G') {
                if (j-1 >= 0) {
                    gali[i][j][0] = check_ok(i, j-1, 0);
                }
                if (i-1 >= 0) {
                    gali[i][j][1] = check_ok(i-1, j, 1);
                }
            }
        }
    }

    vector<pair<int, int>> s[nax+nax];

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            s[i+j].push_back({i, j});
        }
    }

    int ans = 0;
    for(int sz = 0; sz < m+n; sz++) {
        for(const auto& p : s[sz]) {
            int i = p.first, j = p.second;
//            cout << "curr: " << i << " " << j << "\n";

            if (i) {
                dp[i][0] = max({dp[i-1][0], dp[i-1][1], dp[i-1][2]});
                if (gali[i][j][0]) {
                    dp[i][1] = max(dp[i-1][0], dp[i-1][1]) + 1;
                }
                if (gali[i][j][1]) {
                    dp[i][2] = max(dp[i-1][0], dp[i-1][2]) + 1;
                }
            }
            else {
                if (gali[i][j][0]) {
                    dp[i][1] = ans+1;
                }
                if (gali[i][j][1]) {
                    dp[i][2] = ans+1;
                }
            }

//            cout << i << " " << j << ":\n";
            for(int k = 0; k < 3; k++) {
                ans = max(ans, dp[i][k]);
//                cout << dp[i][k] << " ";
            }
//            cout << "\n";
        }
        for(int i = 0; i < n; i++) {
            dp[i][0] = ans;
        }
    }

    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 0 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 0 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 460 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 0 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 0 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 460 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 1 ms 460 KB Output is correct
55 Correct 13 ms 13396 KB Output is correct
56 Correct 2 ms 720 KB Output is correct
57 Correct 10 ms 14412 KB Output is correct
58 Correct 64 ms 20972 KB Output is correct
59 Correct 534 ms 128296 KB Output is correct
60 Correct 547 ms 128196 KB Output is correct
61 Correct 562 ms 128308 KB Output is correct
62 Correct 1 ms 460 KB Output is correct
63 Correct 520 ms 125068 KB Output is correct
64 Correct 486 ms 128308 KB Output is correct
65 Correct 522 ms 128288 KB Output is correct
66 Correct 519 ms 128320 KB Output is correct
67 Correct 498 ms 123144 KB Output is correct
68 Correct 478 ms 128052 KB Output is correct
69 Correct 504 ms 128188 KB Output is correct
70 Correct 58 ms 20784 KB Output is correct
71 Correct 61 ms 20844 KB Output is correct
72 Correct 70 ms 20852 KB Output is correct
73 Correct 58 ms 20804 KB Output is correct
74 Correct 55 ms 20828 KB Output is correct
75 Correct 60 ms 20976 KB Output is correct
76 Correct 73 ms 20852 KB Output is correct
77 Correct 58 ms 20824 KB Output is correct
78 Correct 55 ms 20836 KB Output is correct
79 Correct 59 ms 20772 KB Output is correct
80 Correct 60 ms 20812 KB Output is correct
81 Correct 57 ms 20816 KB Output is correct
82 Correct 57 ms 20804 KB Output is correct
83 Correct 57 ms 20800 KB Output is correct
84 Correct 58 ms 20852 KB Output is correct
85 Correct 59 ms 20804 KB Output is correct
86 Correct 65 ms 20880 KB Output is correct
87 Correct 58 ms 20848 KB Output is correct
88 Correct 60 ms 20800 KB Output is correct
89 Correct 58 ms 20756 KB Output is correct
90 Correct 57 ms 20820 KB Output is correct