답안 #862175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862175 2023-10-17T15:56:47 Z green_gold_dog Dango Maker (JOI18_dango_maker) C++17
100 / 100
307 ms 47184 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;

constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;

random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());

template<typename T>
bool assign_max(T& a, T b) {
        if (b > a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
bool assign_min(T& a, T b) {
        if (b < a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
T square(T a) {
        return a * a;
}

template<>
struct std::hash<pair<ll, ll>> {
        ll operator() (pair<ll, ll> p) const {
                return ((__int128)p.first * MOD + p.second) % INF64;
        }
};

bool check1(ll x, ll y, vector<vector<bool>>& used, vector<vector<char>>& arr) {
        ll n = used.size(), m = used[0].size();
        if (y < 0 || x < 0 || y >= m || x + 2 >= n) {
                return false;
        }
        return !used[x][y] && !used[x + 1][y] && !used[x + 2][y] && arr[x][y] == 'R' && arr[x + 1][y] == 'G' && arr[x + 2][y] == 'W';
}

bool check2(ll x, ll y, vector<vector<bool>>& used, vector<vector<char>>& arr) {
        ll n = used.size(), m = used[0].size();
        if (y < 0 || x < 0 || y + 2 >= m || x >= n) {
                return false;
        }
        return !used[x][y] && !used[x][y + 1] && !used[x][y + 2] && arr[x][y] == 'R' && arr[x][y + 1] == 'G' && arr[x][y + 2] == 'W';
}

void solve() {
        ll n, m;
        cin >> n >> m;
        vector<vector<char>> arr(n, vector<char>(m));
        ll ans = 0;
        vector<vector<bool>> used(n, vector<bool>(m, false));
        vector<vector<ll>> r(n);
        for (ll i = 0; i < n; i++) {
                for (ll j = 0; j < m; j++) {
                        cin >> arr[i][j];
                        if (arr[i][j] == 'R') {
                                r[i].push_back(j);
                        }
                }
        }
        for (ll i = 0; i < n; i++) {
                for (ll j = 0; j < m; j++) {
                        if (check2(i, j, used, arr)) {
                                ans++;
                                used[i][j] = true;
                                used[i][j + 1] = true;
                                used[i][j + 1] = true;
                                continue;
                        }
                        bool b = false;
                        ll c = 0;
                        while (true) {
                                if (!check1(i + c, j - c, used, arr)) {
                                        b = true;
                                        break;
                                }
                                c++;
                                if (!check2(i + c, j - c, used, arr)) {
                                        break;
                                }
                        }
                        if (b) {
                                for (ll k = 1; k <= c; k++) {
                                        if (check2(i + k, j - k, used, arr)) {
                                                ans++;
                                                used[i + k][j - k] = true;
                                                used[i + k][j - k + 1] = true;
                                                used[i + k][j - k + 2] = true;
                                        }
                                }
                        } else {
                                for (ll k = 0; k <= c; k++) {
                                        if (check1(i + k, j - k, used, arr)) {
                                                ans++;
                                                used[i + k][j - k] = true;
                                                used[i + k + 1][j - k] = true;
                                                used[i + k + 2][j - k] = true;
                                        }
                                }
                        }
                }
        }
        cout << ans << '\n';
}

int main() {
        if (IS_FILE) {
                freopen("", "r", stdin);
                freopen("", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t = 1;
        if (IS_TEST_CASES) {
                cin >> t;
        }
        for (ll i = 0; i < t; i++) {
                solve();
        }
}

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:128:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |                 freopen("", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~
dango_maker.cpp:129:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |                 freopen("", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 344 KB Output is correct
5 Correct 1 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 352 KB Output is correct
9 Correct 0 ms 352 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 344 KB Output is correct
5 Correct 1 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 352 KB Output is correct
9 Correct 0 ms 352 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 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 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 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 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 464 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 0 ms 600 KB Output is correct
44 Correct 0 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 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 344 KB Output is correct
5 Correct 1 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 352 KB Output is correct
9 Correct 0 ms 352 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
11 Correct 0 ms 464 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 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 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 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 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 464 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 0 ms 600 KB Output is correct
44 Correct 0 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 1 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 1 ms 860 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 2 ms 856 KB Output is correct
58 Correct 34 ms 6672 KB Output is correct
59 Correct 307 ms 45652 KB Output is correct
60 Correct 292 ms 45640 KB Output is correct
61 Correct 297 ms 45824 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 283 ms 43080 KB Output is correct
64 Correct 174 ms 43344 KB Output is correct
65 Correct 186 ms 43344 KB Output is correct
66 Correct 210 ms 43576 KB Output is correct
67 Correct 253 ms 46876 KB Output is correct
68 Correct 210 ms 47064 KB Output is correct
69 Correct 215 ms 47184 KB Output is correct
70 Correct 23 ms 6744 KB Output is correct
71 Correct 21 ms 6488 KB Output is correct
72 Correct 21 ms 6492 KB Output is correct
73 Correct 21 ms 6492 KB Output is correct
74 Correct 22 ms 6492 KB Output is correct
75 Correct 21 ms 6492 KB Output is correct
76 Correct 23 ms 6488 KB Output is correct
77 Correct 22 ms 6796 KB Output is correct
78 Correct 23 ms 6492 KB Output is correct
79 Correct 23 ms 6492 KB Output is correct
80 Correct 28 ms 6492 KB Output is correct
81 Correct 26 ms 6492 KB Output is correct
82 Correct 23 ms 6492 KB Output is correct
83 Correct 24 ms 6488 KB Output is correct
84 Correct 23 ms 6688 KB Output is correct
85 Correct 23 ms 6492 KB Output is correct
86 Correct 23 ms 6748 KB Output is correct
87 Correct 23 ms 6492 KB Output is correct
88 Correct 24 ms 6492 KB Output is correct
89 Correct 23 ms 6488 KB Output is correct
90 Correct 23 ms 6492 KB Output is correct