답안 #971226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971226 2024-04-28T08:05:09 Z vyshniak_n Dango Maker (JOI18_dango_maker) C++17
100 / 100
168 ms 230456 KB
//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma traget("avx,avx2")

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>

typedef long long ll;
typedef long double ld;

#define el '\n'
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define point pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

const ll INF = 2e18 + 10;
const ll inf = 2e9 + 10;
const ll N = 3e3 + 10;
const ll mod = 1e9 + 7;
const ll K = 200;
const ll LOG = 16;

ll dp[N][N][3];
char a[N][N];

void solve() {
    ll n, m;
    cin >> n >> m;

    for (ll i = 1; i <= n; i++) 
        for (ll j = 1; j <= m; j++)
            cin >> a[i][j];

    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            dp[i][j][0] = max({dp[i - 1][j + 1][0], dp[i - 1][j + 1][1], dp[i - 1][j + 1][2]});
            if (a[i][j] != 'G')
                continue;

            if (a[i][j - 1] == 'R' && a[i][j + 1] == 'W')
                dp[i][j][1] = max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][1]) + 1;
            if (a[i - 1][j] == 'R' && a[i + 1][j] == 'W')
                dp[i][j][2] = max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][2]) + 1;
        }
    }

    ll ans = 0;
    for (ll i = 1; i <= n; i++)
        ans += max({dp[i][1][0], dp[i][1][1], dp[i][1][2]});
    for (ll i = 1; i <= m; i++)
        ans += max({dp[n][i][0], dp[n][i][1], dp[n][i][2]});
    ans -= max({dp[n][1][0], dp[n][1][1], dp[n][1][2]});

    cout << ans << el;
    return;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int tests = 1;
    //cin >> tests;

    while (tests--) 
        solve();
    return 0;
}
/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 472 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 472 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 408 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 396 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 472 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 472 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 408 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 396 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 90 ms 179464 KB Output is correct
56 Correct 1 ms 860 KB Output is correct
57 Correct 20 ms 148296 KB Output is correct
58 Correct 24 ms 75856 KB Output is correct
59 Correct 165 ms 230228 KB Output is correct
60 Correct 168 ms 230004 KB Output is correct
61 Correct 166 ms 230380 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 161 ms 229716 KB Output is correct
64 Correct 124 ms 230228 KB Output is correct
65 Correct 132 ms 230456 KB Output is correct
66 Correct 125 ms 230224 KB Output is correct
67 Correct 122 ms 230228 KB Output is correct
68 Correct 122 ms 230004 KB Output is correct
69 Correct 131 ms 230116 KB Output is correct
70 Correct 19 ms 75868 KB Output is correct
71 Correct 19 ms 75868 KB Output is correct
72 Correct 19 ms 75868 KB Output is correct
73 Correct 18 ms 76120 KB Output is correct
74 Correct 18 ms 76064 KB Output is correct
75 Correct 20 ms 75860 KB Output is correct
76 Correct 20 ms 76124 KB Output is correct
77 Correct 19 ms 75856 KB Output is correct
78 Correct 19 ms 75868 KB Output is correct
79 Correct 19 ms 75868 KB Output is correct
80 Correct 19 ms 76024 KB Output is correct
81 Correct 19 ms 75996 KB Output is correct
82 Correct 19 ms 75868 KB Output is correct
83 Correct 18 ms 75860 KB Output is correct
84 Correct 18 ms 76024 KB Output is correct
85 Correct 19 ms 75860 KB Output is correct
86 Correct 19 ms 75860 KB Output is correct
87 Correct 19 ms 75860 KB Output is correct
88 Correct 19 ms 75856 KB Output is correct
89 Correct 21 ms 75976 KB Output is correct
90 Correct 19 ms 75868 KB Output is correct