답안 #233586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233586 2020-05-21T02:52:18 Z thecodingwizard Dango Maker (JOI18_dango_maker) C++11
13 / 100
6 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ii pair<int, int>
#define pA first
#define pB second
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define vi vector<int>
#define pb push_back

void getCt(int i, int j);

int n, m; 
char A[3000][3000];

string match = "RGW";

bool valid(int i, int j, int dx, int dy) {
    int startMult = A[i][j] == 'R' ? 0 : (A[i][j] == 'G' ? 1 : 2);
    int ct = 0;
    FOR(x, i-dx*startMult, i+dx*(2-startMult)+1) {
        FOR(y, j-dy*startMult, j+dy*(2-startMult)+1) {
            if (x<0||x>=n||y<0||y>=m) return false;
            if (A[x][y] != match[ct++]) return false;
        }
    }
    return true;
}

set<int> seen;
set<int> gotExtra;
map<int, vi> adj;
int getId(int i, int j, int dx, int dy) {
    int startMult = A[i][j] == 'R' ? 0 : (A[i][j] == 'G' ? 1 : 2);
    FOR(x, i-dx*startMult, i+dx*(2-startMult)+1) {
        FOR(y, j-dy*startMult, j+dy*(2-startMult)+1) {
            return x*3000+y+dx*3000*3000*1+dy*3000*3000*2;
        }
    }
    return -1;
}

void process(int i, int j, int dx, int dy) {
    int startMult = A[i][j] == 'R' ? 0 : (A[i][j] == 'G' ? 1 : 2);
    int ct = 0;
    int num = getId(i, j, dx, dy);
    adj[num].pb(num);
    FOR(x, i-dx*startMult, i+dx*(2-startMult)+1) {
        FOR(y, j-dy*startMult, j+dy*(2-startMult)+1) {
            if (ct==0) {
                if (seen.count(num)) return;
                seen.insert(num);
                ct++;
            }
            if (valid(x, y, !dx, !dy)) {
                adj[num].pb(getId(x, y, !dx, !dy));
            }
            getCt(x, y);
        }
    }
}

int curW, curB;
void assign(int u, int c = 0) {
    if (seen.count(u)) return;
    seen.insert(u);
    if (c == 0) curW++;
    else curB++;

    for (auto &v : adj[u]) {
        assign(v, !c);
    }
}

void getCt(int i, int j) {
    if (valid(i, j, 0, 1)) {
        process(i, j, 0, 1);
    }
    if (valid(i, j, 1, 0)) {
        process(i, j, 1, 0);
    }
}

int main() {
    cin >> n >> m;
    F0R(i, n) {
        F0R(j, m) {
            cin >> A[i][j];
        }
    }
    int ans = 0;

    F0R(i, n) {
        F0R(j, m) {
            getCt(i, j);
        }
    }
    seen.clear();
    for (auto x : adj) {
        curW = 0, curB = 0;
        assign(x.pA);
        ans += max(curW, curB);
    }

    cout << ans << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Incorrect 5 ms 384 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Incorrect 5 ms 384 KB Output isn't correct
35 Halted 0 ms 0 KB -