답안 #357632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
357632 2021-01-24T09:23:40 Z cute_hater Dango Maker (JOI18_dango_maker) C++17
100 / 100
1190 ms 257004 KB
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>


/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")*/

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

const int N = 3007;

short f[N][N];
bool usedl[N * N], usedr[N * N];
int g[3][N * N], used[N * N], mtr[N * N], mtl[N * N];

bool kun(int v, int c) {
    used[v] = c;
    for (int i = 0; i < 3 && g[i][v] != -1; ++i) {
        int u = g[i][v];
        if (mtr[u] == -1 || used[mtr[u]] != c && kun(mtr[u], c)) {
            mtr[u] = v;
            return true;
        }
    }
    return false;
}

void dfs(int v) {
    if (v == -1 || usedl[v])
        return;
    usedl[v] = 1;
    for (int i = 0; i < 3 && g[i][v] != -1; ++i) {
        int u = g[i][v];
        if (mtl[v] == u)
            continue;
        if (!usedr[u]) {
            usedr[u] = 1;
            dfs(mtr[u]);
        }
    }
}

void add(int v, int u) {
    loop(i, 3)
        if (g[i][v] == -1) {
            g[i][v] = u; return;
        }
}

void solve() {
    loop(i, N * N)
        mtr[i] = mtl[i] = g[0][i] = g[1][i] = g[2][i] = -1;
    int n, m;
    cin >> n >> m;
    for (int i = 2; i <= n + 1; ++i) {
        for (int j = 2; j <= m + 1; ++j) {
            char c; cin >> c;
            f[i][j] = (c == 'R' ? 1 : (c == 'G' ? 2 : 3));
        }
    }
    for (int i = 2; i <= n + 1; ++i) {
        for (int j = 2; j <= m + 1; ++j) {
            if (f[i][j] == 1 && f[i][j + 1] == 2 && f[i][j + 2] == 3) {
                int v = (i - 2) * m + (j - 2);
                if (f[i + 1][j] == 2 && f[i + 2][j] == 3)
                    add(v, (i - 2) * m + (j - 2));
                if (f[i - 1][j + 1] == 1 && f[i + 1][j + 1] == 3)
                    add(v, (i - 3) * m + (j - 1));
                if (f[i - 2][j + 2] == 1 && f[i - 1][j + 2] == 2)
                    add(v, (i - 4) * m + j);
            }
        }
    }
    int cnt = 0;
    for (int i = 2; i <= n + 1; ++i)
        for (int j = 2; j <= m + 1; ++j)
            kun((i - 2) * m + (j - 2), ++cnt);
    for (int i = 2; i <= n + 1; ++i)
        for (int j = 2; j <= m + 1; ++j)
            if (mtr[(i - 2) * m + (j - 2)] != -1)
                mtl[mtr[(i - 2) * m + (j - 2)]] = (i - 2) * m + (j - 2);
    for (int i = 2; i <= n + 1; ++i)
        for (int j = 2; j <= m + 1; ++j)
            if (mtl[(i - 2) * m + (j - 2)] == -1)
                dfs((i - 2) * m + (j - 2));
    int ans = 0;
    for (int i = 2; i <= n + 1; ++i)
        for (int j = 2; j <= m + 1; ++j)
            ans += (f[i][j] == 1 && f[i][j + 1] == 2 && f[i][j + 2] == 3 && usedl[(i - 2) * m + (j - 2)]) + (f[i][j] == 1 && f[i + 1][j] == 2 && f[i + 2][j] == 3 && !usedr[(i - 2) * m + (j - 2)]);
    cout << ans;
}

signed main() {
    //freopen("b2.txt", "r", stdin);
    //freopen("ans9.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Compilation message

dango_maker.cpp: In function 'bool kun(int, int)':
dango_maker.cpp:62:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   62 |         if (mtr[u] == -1 || used[mtr[u]] != c && kun(mtr[u], c)) {
      |                             ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 177260 KB Output is correct
2 Correct 111 ms 177360 KB Output is correct
3 Correct 112 ms 177420 KB Output is correct
4 Correct 109 ms 177260 KB Output is correct
5 Correct 109 ms 177388 KB Output is correct
6 Correct 110 ms 177388 KB Output is correct
7 Correct 108 ms 177388 KB Output is correct
8 Correct 109 ms 177388 KB Output is correct
9 Correct 113 ms 177260 KB Output is correct
10 Correct 110 ms 177260 KB Output is correct
11 Correct 112 ms 177388 KB Output is correct
12 Correct 114 ms 177360 KB Output is correct
13 Correct 111 ms 177388 KB Output is correct
14 Correct 108 ms 177388 KB Output is correct
15 Correct 110 ms 177388 KB Output is correct
16 Correct 110 ms 177388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 177260 KB Output is correct
2 Correct 111 ms 177360 KB Output is correct
3 Correct 112 ms 177420 KB Output is correct
4 Correct 109 ms 177260 KB Output is correct
5 Correct 109 ms 177388 KB Output is correct
6 Correct 110 ms 177388 KB Output is correct
7 Correct 108 ms 177388 KB Output is correct
8 Correct 109 ms 177388 KB Output is correct
9 Correct 113 ms 177260 KB Output is correct
10 Correct 110 ms 177260 KB Output is correct
11 Correct 112 ms 177388 KB Output is correct
12 Correct 114 ms 177360 KB Output is correct
13 Correct 111 ms 177388 KB Output is correct
14 Correct 108 ms 177388 KB Output is correct
15 Correct 110 ms 177388 KB Output is correct
16 Correct 110 ms 177388 KB Output is correct
17 Correct 112 ms 177516 KB Output is correct
18 Correct 109 ms 177388 KB Output is correct
19 Correct 110 ms 177388 KB Output is correct
20 Correct 115 ms 177388 KB Output is correct
21 Correct 110 ms 177388 KB Output is correct
22 Correct 110 ms 177388 KB Output is correct
23 Correct 110 ms 177388 KB Output is correct
24 Correct 109 ms 177388 KB Output is correct
25 Correct 108 ms 177388 KB Output is correct
26 Correct 111 ms 177260 KB Output is correct
27 Correct 110 ms 177388 KB Output is correct
28 Correct 110 ms 177516 KB Output is correct
29 Correct 110 ms 177388 KB Output is correct
30 Correct 109 ms 177388 KB Output is correct
31 Correct 109 ms 177388 KB Output is correct
32 Correct 109 ms 177364 KB Output is correct
33 Correct 112 ms 177388 KB Output is correct
34 Correct 109 ms 177516 KB Output is correct
35 Correct 110 ms 177516 KB Output is correct
36 Correct 110 ms 177388 KB Output is correct
37 Correct 108 ms 177548 KB Output is correct
38 Correct 112 ms 177388 KB Output is correct
39 Correct 108 ms 177388 KB Output is correct
40 Correct 112 ms 177388 KB Output is correct
41 Correct 113 ms 177388 KB Output is correct
42 Correct 110 ms 177388 KB Output is correct
43 Correct 109 ms 177388 KB Output is correct
44 Correct 112 ms 177516 KB Output is correct
45 Correct 111 ms 177296 KB Output is correct
46 Correct 112 ms 177388 KB Output is correct
47 Correct 108 ms 177388 KB Output is correct
48 Correct 112 ms 177388 KB Output is correct
49 Correct 109 ms 177388 KB Output is correct
50 Correct 110 ms 177388 KB Output is correct
51 Correct 110 ms 177388 KB Output is correct
52 Correct 108 ms 177388 KB Output is correct
53 Correct 111 ms 177412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 177260 KB Output is correct
2 Correct 111 ms 177360 KB Output is correct
3 Correct 112 ms 177420 KB Output is correct
4 Correct 109 ms 177260 KB Output is correct
5 Correct 109 ms 177388 KB Output is correct
6 Correct 110 ms 177388 KB Output is correct
7 Correct 108 ms 177388 KB Output is correct
8 Correct 109 ms 177388 KB Output is correct
9 Correct 113 ms 177260 KB Output is correct
10 Correct 110 ms 177260 KB Output is correct
11 Correct 112 ms 177388 KB Output is correct
12 Correct 114 ms 177360 KB Output is correct
13 Correct 111 ms 177388 KB Output is correct
14 Correct 108 ms 177388 KB Output is correct
15 Correct 110 ms 177388 KB Output is correct
16 Correct 110 ms 177388 KB Output is correct
17 Correct 112 ms 177516 KB Output is correct
18 Correct 109 ms 177388 KB Output is correct
19 Correct 110 ms 177388 KB Output is correct
20 Correct 115 ms 177388 KB Output is correct
21 Correct 110 ms 177388 KB Output is correct
22 Correct 110 ms 177388 KB Output is correct
23 Correct 110 ms 177388 KB Output is correct
24 Correct 109 ms 177388 KB Output is correct
25 Correct 108 ms 177388 KB Output is correct
26 Correct 111 ms 177260 KB Output is correct
27 Correct 110 ms 177388 KB Output is correct
28 Correct 110 ms 177516 KB Output is correct
29 Correct 110 ms 177388 KB Output is correct
30 Correct 109 ms 177388 KB Output is correct
31 Correct 109 ms 177388 KB Output is correct
32 Correct 109 ms 177364 KB Output is correct
33 Correct 112 ms 177388 KB Output is correct
34 Correct 109 ms 177516 KB Output is correct
35 Correct 110 ms 177516 KB Output is correct
36 Correct 110 ms 177388 KB Output is correct
37 Correct 108 ms 177548 KB Output is correct
38 Correct 112 ms 177388 KB Output is correct
39 Correct 108 ms 177388 KB Output is correct
40 Correct 112 ms 177388 KB Output is correct
41 Correct 113 ms 177388 KB Output is correct
42 Correct 110 ms 177388 KB Output is correct
43 Correct 109 ms 177388 KB Output is correct
44 Correct 112 ms 177516 KB Output is correct
45 Correct 111 ms 177296 KB Output is correct
46 Correct 112 ms 177388 KB Output is correct
47 Correct 108 ms 177388 KB Output is correct
48 Correct 112 ms 177388 KB Output is correct
49 Correct 109 ms 177388 KB Output is correct
50 Correct 110 ms 177388 KB Output is correct
51 Correct 110 ms 177388 KB Output is correct
52 Correct 108 ms 177388 KB Output is correct
53 Correct 111 ms 177412 KB Output is correct
54 Correct 111 ms 177388 KB Output is correct
55 Correct 117 ms 189420 KB Output is correct
56 Correct 110 ms 177516 KB Output is correct
57 Correct 113 ms 185452 KB Output is correct
58 Correct 170 ms 189036 KB Output is correct
59 Correct 603 ms 247404 KB Output is correct
60 Correct 602 ms 247532 KB Output is correct
61 Correct 601 ms 247532 KB Output is correct
62 Correct 109 ms 177388 KB Output is correct
63 Correct 588 ms 245800 KB Output is correct
64 Correct 792 ms 256928 KB Output is correct
65 Correct 911 ms 257004 KB Output is correct
66 Correct 1190 ms 256876 KB Output is correct
67 Correct 430 ms 247952 KB Output is correct
68 Correct 431 ms 247788 KB Output is correct
69 Correct 435 ms 247788 KB Output is correct
70 Correct 178 ms 190188 KB Output is correct
71 Correct 181 ms 190188 KB Output is correct
72 Correct 175 ms 190188 KB Output is correct
73 Correct 178 ms 190188 KB Output is correct
74 Correct 180 ms 190188 KB Output is correct
75 Correct 180 ms 190188 KB Output is correct
76 Correct 177 ms 190188 KB Output is correct
77 Correct 179 ms 190188 KB Output is correct
78 Correct 181 ms 190188 KB Output is correct
79 Correct 182 ms 190188 KB Output is correct
80 Correct 183 ms 190208 KB Output is correct
81 Correct 187 ms 190188 KB Output is correct
82 Correct 181 ms 190188 KB Output is correct
83 Correct 189 ms 190188 KB Output is correct
84 Correct 187 ms 190296 KB Output is correct
85 Correct 181 ms 190188 KB Output is correct
86 Correct 183 ms 190188 KB Output is correct
87 Correct 187 ms 190188 KB Output is correct
88 Correct 181 ms 190188 KB Output is correct
89 Correct 182 ms 190188 KB Output is correct
90 Correct 185 ms 190188 KB Output is correct