답안 #1050711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050711 2024-08-09T13:07:05 Z vjudge1 Dango Maker (JOI18_dango_maker) C++17
100 / 100
140 ms 159944 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define static_assert(...);
#include <tr2/dynamic_bitset>
using custom_bitset = tr2::dynamic_bitset<__uint128_t>;
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define bigInt __int128
#define dl double long
#define fl float
#define all(s) s.begin(), s.end()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pob_front
#define ins insert
#define F first
#define S second
#define len length
const int N = 100010;
const int M = 1010;
const int LN = 131072;
const int INF = 1000000000000000000;
const int MOD = 1e9 + 7;
const int BLOCK = 500;
int binpow(int a, int b, int MOD) {
    int res = 1;
    while (b > 0) {
        if (b & 1) {
            res = res * a;
            res %= MOD;
        }
        a = a * a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}
int MMI(int a, int MOD) {
    int ret = binpow(a, MOD - 2, MOD);
    return ret;
}
// int mdiv(int a, int b) {
//     int ret = a*MMI(b);
//     ret %= MOD;
//     return ret;
// }
int mmul(int a, int b) {
    int ret = (a % MOD) * (b % MOD);
    ret %= MOD;
    return ret;
}
int madd(int a, int b) {
    int ret = (a % MOD) + (b % MOD);
    ret %= MOD;
    return ret;
}
int msub(int a, int b) {
    int ret = (a % MOD) - (b % MOD);
    ret += MOD;
    ret %= MOD;
    return ret;
}
int GCD(int a, int b) {
    if (b == 0) {
        return a;
    }
    return GCD(b, a % b);
}
int LCM(int a, int b) {
    return a*b / GCD(a, b);
}
struct pqComp
{
    bool operator()(const pair<int, int>& p1, const pair<int, int>& p2) const
    {
        return (p1.F < p2.F) || (p1.F == p2.F && p1.S < p2.S);
    }
};
bool pCompF(pair<int, int>& p1, pair<int, int>& p2)
{
    return p1.F < p2.F;
}
bool pCompS(pair<int, int>& p1, pair<int, int>& p2)
{
    return p1.S < p2.S;
}
bool pCompFS(pair<int, int>& p1, pair<int, int>& p2)
{
    return (p1.S < p2.S) || (p1.S == p2.S && p1.F < p2.F);
}
vector <pair<int, int>> DS {{1, 0}, {0, 1}};//{{0, -1}, {1, 0}, {0, 1}, {-1, 0}};//, {-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
int n, m, dp[2][3*M][3*M];
char a[3*M][3*M];

int ver(int i, int j) {
    return (a[i][j] == 'R' && a[i + 1][j] == 'G' && a[i + 2][j] == 'W');
}

int hor(int i, int j) {
    return (a[i][j] == 'R' && a[i][j + 1] == 'G' && a[i][j + 2] == 'W');
}

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> a[i][j];
        }
    }
    for (int i = n; i >= 1; --i) {
        for (int j = m; j >= 1; --j) {
            dp[0][i][j] = max(dp[0][i + 1][j - 1], dp[1][i + 1][j - 1]) + hor(i, j);
            dp[1][i][j] = dp[1][i + 1][j - 1];
            if (j > 3) {
                dp[1][i][j] = max({dp[1][i][j], dp[0][i + 3][j - 3], dp[1][i - 3][j - 3]});
            }
            dp[1][i][j] += ver(i, j);
        }
    }
    int ans = 0;
    for (int i = 1; i <= m; ++i) {
        ans += max(dp[0][1][i], dp[1][1][i]);
    }
    for (int i = 2; i <= n; ++i) {
        ans += max(dp[0][i][m], dp[1][i][m]);
    }
    cout << ans;
}
 
signed main() {
    speed;
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
}
/*
НЕ ЗАХОДИТ РЕШЕНИЕ?
1) ПРОВЕРЬ НА ОЧЕВИДНЫЕ ОШИБКИ В КОДЕ
2) ПРОВЕРЬ НА ПЕРЕПОЛНЕНИЯ
3) УБЕДИСЬ В ПРАВИЛЬНОСТИ АЛГОРИТМА
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 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 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 464 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 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 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 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 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 468 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 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 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 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 464 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 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 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 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 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 468 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 468 KB Output is correct
55 Correct 8 ms 43356 KB Output is correct
56 Correct 1 ms 600 KB Output is correct
57 Correct 6 ms 34976 KB Output is correct
58 Correct 18 ms 37460 KB Output is correct
59 Correct 140 ms 159864 KB Output is correct
60 Correct 139 ms 159868 KB Output is correct
61 Correct 137 ms 159824 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 136 ms 159680 KB Output is correct
64 Correct 111 ms 159828 KB Output is correct
65 Correct 107 ms 159824 KB Output is correct
66 Correct 107 ms 159824 KB Output is correct
67 Correct 110 ms 159828 KB Output is correct
68 Correct 110 ms 159944 KB Output is correct
69 Correct 108 ms 159824 KB Output is correct
70 Correct 14 ms 38644 KB Output is correct
71 Correct 14 ms 37464 KB Output is correct
72 Correct 13 ms 38492 KB Output is correct
73 Correct 14 ms 37464 KB Output is correct
74 Correct 16 ms 38448 KB Output is correct
75 Correct 18 ms 37468 KB Output is correct
76 Correct 14 ms 37464 KB Output is correct
77 Correct 15 ms 38660 KB Output is correct
78 Correct 14 ms 37468 KB Output is correct
79 Correct 14 ms 38492 KB Output is correct
80 Correct 14 ms 38492 KB Output is correct
81 Correct 14 ms 37600 KB Output is correct
82 Correct 14 ms 38496 KB Output is correct
83 Correct 13 ms 38492 KB Output is correct
84 Correct 14 ms 37620 KB Output is correct
85 Correct 14 ms 38492 KB Output is correct
86 Correct 13 ms 38516 KB Output is correct
87 Correct 14 ms 37468 KB Output is correct
88 Correct 14 ms 37536 KB Output is correct
89 Correct 14 ms 38432 KB Output is correct
90 Correct 16 ms 37468 KB Output is correct