답안 #531232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531232 2022-02-28T06:09:50 Z 79brue 길고양이 (JOI20_stray) C++14
100 / 100
54 ms 17012 KB
#include "Anthony.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

namespace {
    int n, m, a, b;
    vector<pair<int, int> > link[20002];
    vector<int> ans;
    int dist[20002];
    int col[20002], road[20002];

    void bfs(){
        queue<pair<int, int> > que;
        dist[0] = 1;
        que.push(make_pair(0, 1));
        while(!que.empty()){
            pair<int, int> tmp = que.front(); que.pop();
            int x = tmp.first, d = tmp.second;
            dist[x] = d;

            for(auto y: link[x]){
                if(dist[y.first]) continue;
                dist[y.first] = d+1;
                que.push(make_pair(y.first, d+1));
            }
        }
    }

    const int pattern[] = {0, 0, 1, 0, 1, 1};
    void dfs(int x, int par = -1, int cnt = 0){
        if(x==0){
            for(auto y: link[x]){
                col[y.second] = pattern[cnt%6];
                road[y.first] = y.second;
                dfs(y.first, x, (cnt+1)%6);
            }
            return;
        }

        if((int)link[x].size() == 1) return;
        if((int)link[x].size() == 2){
            for(auto y: link[x]){
                if(y.first == par) continue;
                col[y.second] = pattern[cnt];
                road[y.first] = y.second;
                dfs(y.first, x, (cnt+1)%6);
            }
            return;
        }

        if(col[road[x]]) cnt = 1;
        else cnt = 3;
        for(auto y: link[x]){
            if(par == y.first) continue;
            col[y.second] = !col[road[x]];
            road[y.first] = y.second;
            dfs(y.first, x, cnt);
        }
    }
}

vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V) {
    n = N, m = M, a = A, b = B;
    for(int i=0; i<m; i++) link[U[i]].push_back(make_pair(V[i], i)), link[V[i]].push_back(make_pair(U[i], i));

    if(A >= 3){
        bfs();
        for(int i=0; i<m; i++){
            ans.push_back((min(dist[U[i]], dist[V[i]]) + 2) % 3);
        }
        return ans;
    }
    else{
        ans.resize(m);
        dfs(0);
        return vector<int> (col, col+m);
    }
}
#include "Catherine.h"
#include <bits/stdc++.h>

using namespace std;

namespace {
    int A, B;

    int pattern[] = {1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0};
    bool strange = 1;
    int cnt = 0;
    int prv = -1;
    vector<int> vb;
}

void Init(int A, int B) {
    ::A = A;
    ::B = B;
    prv = -1, cnt = 0, strange = 1;
}

int Move(vector<int> y){
    if(A >= 3){
        vector<int> lVec;
        for(int i=0; i<A; i++) for(int j=0; j<y[i]; j++) lVec.push_back(i);
        y = lVec;
        int MIN = *min_element(y.begin(), y.end());
        int MAX = *max_element(y.begin(), y.end());
        if(MIN==MAX) return MIN;
        return MAX==1 ? 0 : MIN==1 ? 1 : 2;
    }

    int c0 = y[0], c1 = y[1];
    cnt++;
    if(cnt > 6) strange = 0;

    if(!strange){
        if(!c0) return prv=1;
        if(!c1) return prv=0;

        if(prv == 0) c0++;
        if(prv == 1) c1++;
        if(c0 == 1) return prv=0;
        if(c1 == 1) return prv=1;
    }

    if(prv == 0) c0++;
    if(prv == 1) c1++;

    if(prv == -1){
        if(c0+c1==1){
            strange = 0;
            if(c0) return prv=0;
            return prv=1;
        }
        if(c0+c1>2){
            strange = 0;
            if(c0==1) return prv=0;
            if(c1==1) return prv=1;
        }

        if(c0==2){
            vb.push_back(0);
            vb.push_back(0);
            return prv=0;
        }
        else if(c1==2){
            vb.push_back(1);
            vb.push_back(1);
            return prv=1;
        }
        else{
            vb.push_back(0);
            vb.push_back(1);
            return prv=1;
        }
    }

    if(c0+c1>2){
        strange = 0;
        if(c0==1){
            if(prv==0) return -1;
            return prv = 0;
        }
        if(c1==1){
            if(prv==1) return -1;
            return prv=1;
        }
    }

    if(c0+c1==1){
        strange = 0;
        return -1;
    }
    vb.push_back(y[0] ? 0 : 1);

    bool possible = 0;
    for(int i=0; i<6; i++){
        bool diff=0;
        for(int j=0; j<(int)vb.size(); j++){
            if(pattern[i+j] != vb[j]) diff=1;
        }
        if(!diff) possible=1;
    }
    if(!possible){
        strange=0;
        return -1;
    }
    return prv = y[0]?0:1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 15896 KB Output is correct
2 Correct 1 ms 1060 KB Output is correct
3 Correct 36 ms 15356 KB Output is correct
4 Correct 45 ms 17012 KB Output is correct
5 Correct 51 ms 17008 KB Output is correct
6 Correct 40 ms 15772 KB Output is correct
7 Correct 36 ms 15688 KB Output is correct
8 Correct 40 ms 16408 KB Output is correct
9 Correct 49 ms 16548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 15896 KB Output is correct
2 Correct 1 ms 1060 KB Output is correct
3 Correct 36 ms 15356 KB Output is correct
4 Correct 45 ms 17012 KB Output is correct
5 Correct 51 ms 17008 KB Output is correct
6 Correct 40 ms 15772 KB Output is correct
7 Correct 36 ms 15688 KB Output is correct
8 Correct 40 ms 16408 KB Output is correct
9 Correct 49 ms 16548 KB Output is correct
10 Correct 40 ms 13800 KB Output is correct
11 Correct 37 ms 13896 KB Output is correct
12 Correct 31 ms 13788 KB Output is correct
13 Correct 44 ms 13852 KB Output is correct
14 Correct 43 ms 14044 KB Output is correct
15 Correct 43 ms 14600 KB Output is correct
16 Correct 40 ms 16532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13492 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 30 ms 13072 KB Output is correct
4 Correct 43 ms 14684 KB Output is correct
5 Correct 46 ms 15052 KB Output is correct
6 Correct 37 ms 13556 KB Output is correct
7 Correct 39 ms 13620 KB Output is correct
8 Correct 41 ms 14164 KB Output is correct
9 Correct 54 ms 14100 KB Output is correct
10 Correct 52 ms 13844 KB Output is correct
11 Correct 36 ms 13916 KB Output is correct
12 Correct 37 ms 13892 KB Output is correct
13 Correct 37 ms 13892 KB Output is correct
14 Correct 46 ms 14316 KB Output is correct
15 Correct 41 ms 14104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 13492 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 30 ms 13072 KB Output is correct
4 Correct 43 ms 14684 KB Output is correct
5 Correct 46 ms 15052 KB Output is correct
6 Correct 37 ms 13556 KB Output is correct
7 Correct 39 ms 13620 KB Output is correct
8 Correct 41 ms 14164 KB Output is correct
9 Correct 54 ms 14100 KB Output is correct
10 Correct 52 ms 13844 KB Output is correct
11 Correct 36 ms 13916 KB Output is correct
12 Correct 37 ms 13892 KB Output is correct
13 Correct 37 ms 13892 KB Output is correct
14 Correct 46 ms 14316 KB Output is correct
15 Correct 41 ms 14104 KB Output is correct
16 Correct 28 ms 12184 KB Output is correct
17 Correct 28 ms 12048 KB Output is correct
18 Correct 38 ms 11968 KB Output is correct
19 Correct 32 ms 11928 KB Output is correct
20 Correct 39 ms 12664 KB Output is correct
21 Correct 34 ms 12408 KB Output is correct
22 Correct 38 ms 14328 KB Output is correct
23 Correct 31 ms 12068 KB Output is correct
24 Correct 38 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1260 KB Output is correct
2 Correct 1 ms 1008 KB Output is correct
3 Correct 2 ms 1272 KB Output is correct
4 Correct 2 ms 1472 KB Output is correct
5 Correct 2 ms 1400 KB Output is correct
6 Correct 2 ms 1388 KB Output is correct
7 Correct 2 ms 1392 KB Output is correct
8 Correct 3 ms 1328 KB Output is correct
9 Correct 2 ms 1392 KB Output is correct
10 Correct 2 ms 1400 KB Output is correct
11 Correct 2 ms 1400 KB Output is correct
12 Correct 2 ms 1264 KB Output is correct
13 Correct 2 ms 1272 KB Output is correct
14 Correct 2 ms 1328 KB Output is correct
15 Correct 3 ms 1392 KB Output is correct
16 Correct 2 ms 1264 KB Output is correct
17 Correct 3 ms 1324 KB Output is correct
18 Correct 3 ms 1324 KB Output is correct
19 Correct 2 ms 1312 KB Output is correct
20 Correct 3 ms 1264 KB Output is correct
21 Correct 2 ms 1264 KB Output is correct
22 Correct 2 ms 1320 KB Output is correct
23 Correct 2 ms 1324 KB Output is correct
24 Correct 2 ms 1264 KB Output is correct
25 Correct 2 ms 1320 KB Output is correct
26 Correct 2 ms 1264 KB Output is correct
27 Correct 2 ms 1272 KB Output is correct
28 Correct 2 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 11728 KB Output is correct
2 Correct 34 ms 12928 KB Output is correct
3 Correct 1 ms 1008 KB Output is correct
4 Correct 26 ms 11520 KB Output is correct
5 Correct 41 ms 14396 KB Output is correct
6 Correct 42 ms 14308 KB Output is correct
7 Correct 34 ms 13556 KB Output is correct
8 Correct 32 ms 13480 KB Output is correct
9 Correct 41 ms 14312 KB Output is correct
10 Correct 41 ms 14352 KB Output is correct
11 Correct 41 ms 14316 KB Output is correct
12 Correct 48 ms 14320 KB Output is correct
13 Correct 39 ms 14376 KB Output is correct
14 Correct 41 ms 14492 KB Output is correct
15 Correct 39 ms 14384 KB Output is correct
16 Correct 39 ms 14372 KB Output is correct
17 Correct 36 ms 13972 KB Output is correct
18 Correct 37 ms 14220 KB Output is correct
19 Correct 35 ms 14008 KB Output is correct
20 Correct 36 ms 14188 KB Output is correct
21 Correct 36 ms 14124 KB Output is correct
22 Correct 36 ms 14108 KB Output is correct
23 Correct 30 ms 11644 KB Output is correct
24 Correct 34 ms 11856 KB Output is correct
25 Correct 32 ms 12228 KB Output is correct
26 Correct 31 ms 12240 KB Output is correct
27 Correct 37 ms 12960 KB Output is correct
28 Correct 35 ms 13032 KB Output is correct
29 Correct 39 ms 13080 KB Output is correct
30 Correct 36 ms 13120 KB Output is correct
31 Correct 30 ms 11756 KB Output is correct
32 Correct 31 ms 11672 KB Output is correct
33 Correct 32 ms 12084 KB Output is correct
34 Correct 31 ms 12100 KB Output is correct
35 Correct 34 ms 12904 KB Output is correct
36 Correct 35 ms 12788 KB Output is correct
37 Correct 35 ms 12848 KB Output is correct
38 Correct 35 ms 12940 KB Output is correct
39 Correct 33 ms 12836 KB Output is correct
40 Correct 35 ms 12816 KB Output is correct
41 Correct 35 ms 13568 KB Output is correct
42 Correct 36 ms 13604 KB Output is correct
43 Correct 36 ms 13688 KB Output is correct
44 Correct 35 ms 13628 KB Output is correct
45 Correct 36 ms 13672 KB Output is correct
46 Correct 38 ms 13600 KB Output is correct
47 Correct 34 ms 12744 KB Output is correct
48 Correct 34 ms 12700 KB Output is correct
49 Correct 32 ms 12680 KB Output is correct
50 Correct 35 ms 12780 KB Output is correct
51 Correct 31 ms 11872 KB Output is correct
52 Correct 31 ms 11928 KB Output is correct
53 Correct 30 ms 11928 KB Output is correct
54 Correct 32 ms 12076 KB Output is correct
55 Correct 30 ms 11896 KB Output is correct
56 Correct 30 ms 11864 KB Output is correct
57 Correct 31 ms 11812 KB Output is correct
58 Correct 32 ms 11820 KB Output is correct
59 Correct 32 ms 11932 KB Output is correct
60 Correct 31 ms 11928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 11680 KB Output is correct
2 Correct 37 ms 12808 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 26 ms 11532 KB Output is correct
5 Correct 40 ms 14376 KB Output is correct
6 Correct 40 ms 14296 KB Output is correct
7 Correct 33 ms 13440 KB Output is correct
8 Correct 32 ms 13536 KB Output is correct
9 Correct 39 ms 14280 KB Output is correct
10 Correct 43 ms 14624 KB Output is correct
11 Correct 40 ms 14324 KB Output is correct
12 Correct 39 ms 14316 KB Output is correct
13 Correct 37 ms 14340 KB Output is correct
14 Correct 39 ms 14316 KB Output is correct
15 Correct 40 ms 14360 KB Output is correct
16 Correct 44 ms 14308 KB Output is correct
17 Correct 38 ms 14000 KB Output is correct
18 Correct 36 ms 14136 KB Output is correct
19 Correct 37 ms 14096 KB Output is correct
20 Correct 35 ms 14028 KB Output is correct
21 Correct 38 ms 14100 KB Output is correct
22 Correct 36 ms 14200 KB Output is correct
23 Correct 32 ms 11896 KB Output is correct
24 Correct 33 ms 11848 KB Output is correct
25 Correct 31 ms 12228 KB Output is correct
26 Correct 31 ms 12128 KB Output is correct
27 Correct 36 ms 13020 KB Output is correct
28 Correct 37 ms 13080 KB Output is correct
29 Correct 41 ms 13096 KB Output is correct
30 Correct 37 ms 13068 KB Output is correct
31 Correct 34 ms 11792 KB Output is correct
32 Correct 28 ms 11692 KB Output is correct
33 Correct 31 ms 12216 KB Output is correct
34 Correct 34 ms 12180 KB Output is correct
35 Correct 35 ms 12872 KB Output is correct
36 Correct 34 ms 12848 KB Output is correct
37 Correct 42 ms 12912 KB Output is correct
38 Correct 34 ms 12824 KB Output is correct
39 Correct 36 ms 12764 KB Output is correct
40 Correct 34 ms 12832 KB Output is correct
41 Correct 35 ms 13576 KB Output is correct
42 Correct 37 ms 13500 KB Output is correct
43 Correct 36 ms 13688 KB Output is correct
44 Correct 37 ms 13596 KB Output is correct
45 Correct 40 ms 13740 KB Output is correct
46 Correct 36 ms 13612 KB Output is correct
47 Correct 34 ms 12788 KB Output is correct
48 Correct 34 ms 12768 KB Output is correct
49 Correct 34 ms 12692 KB Output is correct
50 Correct 35 ms 12788 KB Output is correct
51 Correct 32 ms 11948 KB Output is correct
52 Correct 31 ms 11840 KB Output is correct
53 Correct 34 ms 11952 KB Output is correct
54 Correct 32 ms 11812 KB Output is correct
55 Correct 31 ms 11876 KB Output is correct
56 Correct 31 ms 11828 KB Output is correct
57 Correct 31 ms 11820 KB Output is correct
58 Correct 36 ms 11824 KB Output is correct
59 Correct 33 ms 11896 KB Output is correct
60 Correct 31 ms 11960 KB Output is correct