Submission #160522

# Submission time Handle Problem Language Result Execution time Memory
160522 2019-10-28T09:24:00 Z godwind Dango Maker (JOI18_dango_maker) C++14
100 / 100
1185 ms 213088 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
 
 
using namespace std;
 
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
 
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}
 
#define int long long
#define left left228
#define right right228
#define prev prev228
#define list list228
#define mp make_pair
#define all(v) v.begin(), v.end()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define x first
#define y second

const int N = 3005;

bool is_right[N][N], is_up[N][N];
char a[N][N];
vector< pair<int, int> > sum[N + N];
int dp[N + N][3];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> a[i][j];
            sum[i + j].push_back({i, j});
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] == 'G') {
                if (i - 1 >= 1 && i + 1 <= n && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
                    is_up[i][j] = 1;
                }
                if (j - 1 >= 1 && j + 1 <= m && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
                    is_right[i][j] = 1;
                }
            }
        }
    }
    int res = 0;
    for (int S = 2; S <= n + m; ++S) {
        int sz = (int)sum[S].size();
        for (int i = 1; i <= sz; ++i) {
            dp[i][0] = dp[i][1] = dp[i][2] = 0;
        }
        dp[0][0] = 0;
        for (int i = 1; i <= sz; ++i) {
            int x = sum[S][i - 1].first, y = sum[S][i - 1].second;
            dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));
            for (int j = 1; j < 3; ++j) {
                if (a[x][y] == 'G') {
                    if (j && ((j == 1 && is_right[x][y]) || (j == 2 && is_up[x][y]))) {
                        for (int jj = 0; jj < 3; ++jj) {
                            if (jj != 3 - j) {
                                uax(dp[i][j], dp[i - 1][jj] + 1);
                            }
                        }
                    }
                }
            }
        }
        res += max(dp[sz][0], max(dp[sz][1], dp[sz][2]));
    }

    cout << res << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 632 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 680 KB Output is correct
29 Correct 2 ms 632 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 2 ms 632 KB Output is correct
34 Correct 2 ms 632 KB Output is correct
35 Correct 2 ms 632 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 2 ms 632 KB Output is correct
38 Correct 2 ms 632 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 2 ms 504 KB Output is correct
41 Correct 2 ms 632 KB Output is correct
42 Correct 2 ms 632 KB Output is correct
43 Correct 2 ms 632 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 2 ms 504 KB Output is correct
48 Correct 2 ms 504 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 0 ms 504 KB Output is correct
51 Correct 2 ms 632 KB Output is correct
52 Correct 2 ms 632 KB Output is correct
53 Correct 2 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 632 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 2 ms 680 KB Output is correct
29 Correct 2 ms 632 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 2 ms 632 KB Output is correct
34 Correct 2 ms 632 KB Output is correct
35 Correct 2 ms 632 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 2 ms 632 KB Output is correct
38 Correct 2 ms 632 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 2 ms 504 KB Output is correct
41 Correct 2 ms 632 KB Output is correct
42 Correct 2 ms 632 KB Output is correct
43 Correct 2 ms 632 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 2 ms 504 KB Output is correct
48 Correct 2 ms 504 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 0 ms 504 KB Output is correct
51 Correct 2 ms 632 KB Output is correct
52 Correct 2 ms 632 KB Output is correct
53 Correct 2 ms 632 KB Output is correct
54 Correct 2 ms 632 KB Output is correct
55 Correct 12 ms 9848 KB Output is correct
56 Correct 4 ms 1016 KB Output is correct
57 Correct 16 ms 14840 KB Output is correct
58 Correct 97 ms 29768 KB Output is correct
59 Correct 1123 ms 212220 KB Output is correct
60 Correct 1061 ms 212980 KB Output is correct
61 Correct 1185 ms 212964 KB Output is correct
62 Correct 3 ms 760 KB Output is correct
63 Correct 1010 ms 206196 KB Output is correct
64 Correct 951 ms 213088 KB Output is correct
65 Correct 939 ms 212828 KB Output is correct
66 Correct 911 ms 212856 KB Output is correct
67 Correct 886 ms 202308 KB Output is correct
68 Correct 898 ms 202428 KB Output is correct
69 Correct 933 ms 208828 KB Output is correct
70 Correct 83 ms 30712 KB Output is correct
71 Correct 84 ms 30712 KB Output is correct
72 Correct 84 ms 30712 KB Output is correct
73 Correct 87 ms 30932 KB Output is correct
74 Correct 83 ms 30712 KB Output is correct
75 Correct 83 ms 30968 KB Output is correct
76 Correct 86 ms 30840 KB Output is correct
77 Correct 85 ms 30832 KB Output is correct
78 Correct 86 ms 30840 KB Output is correct
79 Correct 80 ms 30840 KB Output is correct
80 Correct 80 ms 30712 KB Output is correct
81 Correct 81 ms 30940 KB Output is correct
82 Correct 76 ms 30712 KB Output is correct
83 Correct 84 ms 30840 KB Output is correct
84 Correct 84 ms 30756 KB Output is correct
85 Correct 83 ms 30840 KB Output is correct
86 Correct 80 ms 30712 KB Output is correct
87 Correct 86 ms 30840 KB Output is correct
88 Correct 77 ms 30840 KB Output is correct
89 Correct 80 ms 30920 KB Output is correct
90 Correct 85 ms 30824 KB Output is correct