답안 #904170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
904170 2024-01-11T20:55:55 Z guechotjrhh 길고양이 (JOI20_stray) C++14
100 / 100
48 ms 16260 KB
#include "Anthony.h"
#include <vector>
#include<queue>
#include<iostream>
using namespace std;
#define pi pair<int,int>
#define x first
#define y second


vector<int> sequ = { 0, 1, 0, 0, 1, 1 };
int n, m;
void dfs(int i, int col, int seq, int f, vector<vector<pi>>& g, vector<int>&res) {
    if (g[i].size() == 1 && f != -1) return;
    if ((g[i].size() == 2 && f != -1) || g[i].size() == 1) {
        if (seq == -1) seq = (col == 0) ? 0 : 5;
        (seq += 1) %= 6;
        int ni = (g[i][0].x == f) ? 1 : 0;
        res[g[i][ni].y] = sequ[seq];
        dfs(g[i][ni].x, sequ[seq], seq, i, g, res);
        return;
    }
    for (pi p : g[i]) {
        if (p.x == f) continue;
        res[p.y] = 1 - col;
        dfs(p.x, 1 - col, -1, i, g, res);
    }
    
}
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V) {
    n = N; m = M;

    vector<vector<pi>> g(n);
    for (int i = 0; i < m; i++) {
        g[U[i]].push_back({ V[i],i });
        g[V[i]].push_back({ U[i],i });
    }
    if (A >= 3) {
        vector<int> dist(n, 1e9);
        dist[0] = 0;
        queue<int> q;
        q.push(0);
        while (q.size()) {
            int u = q.front(); q.pop();
            for (pi j : g[u]) {
                if (dist[j.x] > dist[u] + 1) {
                    dist[j.x] = dist[u] + 1;
                    q.push(j.x);
                }
            }
        }
        vector<int> res(m);
        for (int i = 0; i < m; i++) {
            res[i] = min(dist[U[i]] , dist[V[i]]) % 3;
        }
        return res;
    }
    else {
        vector<int> res(m);
        dfs(0, 1, -1, -1, g, res);
        //for (int i = 0; i < m; i++) { cout << U[i] << ' ' << V[i] << ' ' << res[i] << endl; }
        return res;
    }
}
#include "Catherine.h"
#include <vector>
#include <iostream>
using namespace std;

int v = -1,a,b;
bool flag = 0;
vector<int> last;
void Init(int A, int B) {
    a = A;
    b = B;
    v = -1;
    flag = 0;
    last.clear();
}
vector<int> seqi = { 0, 1, 0, 0, 1, 1 };
bool check() {
    //for (int i : last) cout << i << ' '; cout << endl;
    for (int i = 0; i < 6; i++) {
        bool fl = 1;
        for (int j = 0; j < 5; j++) {
            if (last[j] != seqi[(i + j) % 6]) fl = 0;
        }
        if (fl) return 0;
    }
    return 1;
}
int Move(vector<int> y) {
    if (a >= 3) {
        if (v != -1) {
            (v += 2) %= 3;
            return v;
        }
        if (y[0] && !y[2]) v = 0;
        if (!y[1] && y[2]) v = 2;
        if (!y[0] && y[1]) v = 1;
        return v;
    }
    else {
        if (flag) {
            //cout << "C" << endl;
            if (y[0] && y[1]) v = 1 - v;
            else if (y[0]) v = 0;
            else if (y[1]) v = 1;
            return v;
        }
        else if (v == -1) {
            //cout << "A" << endl;
            if (y[0] + y[1] > 2) {
                if (y[0] > 1) v = 1;
                else v = 0;
                flag = 1;
                return v;
            }
            if (y[0] + y[1] == 1) {
                if (y[0]) v = 0;
                else v = 1;
                flag = 1;
                return v;
            }
            if (y[0]) last.push_back(0);
            if (y[1]) { v = 1; last.push_back(1);}
            if (y[0] == 2) { v = 0; last.push_back(0); }
            if (y[1] == 2) { last.push_back(1); }
            return v;
        }
        else {
            //cout << "B" << endl;
            if (y[0] + y[1] > 1) {
                flag = 1;
                if (y[v]) {
                    v = 1 - v;
                    return v;
                }
                else return -1;
            }
            if (y[0] + y[1] == 0) {
                flag = 1;
                return -1;
            }
            if (y[0]) v = 0;
            else v = 1;
            last.push_back(v);
            if (last.size() < 5) return v;
            flag = 1;
            if (check()) return v;
            v = last[3];
            return -1;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 15168 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 26 ms 14548 KB Output is correct
4 Correct 39 ms 16248 KB Output is correct
5 Correct 45 ms 16260 KB Output is correct
6 Correct 34 ms 15008 KB Output is correct
7 Correct 34 ms 15012 KB Output is correct
8 Correct 38 ms 15732 KB Output is correct
9 Correct 46 ms 15752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 15168 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 26 ms 14548 KB Output is correct
4 Correct 39 ms 16248 KB Output is correct
5 Correct 45 ms 16260 KB Output is correct
6 Correct 34 ms 15008 KB Output is correct
7 Correct 34 ms 15012 KB Output is correct
8 Correct 38 ms 15732 KB Output is correct
9 Correct 46 ms 15752 KB Output is correct
10 Correct 26 ms 13180 KB Output is correct
11 Correct 27 ms 13176 KB Output is correct
12 Correct 26 ms 13176 KB Output is correct
13 Correct 27 ms 12888 KB Output is correct
14 Correct 26 ms 13388 KB Output is correct
15 Correct 31 ms 13688 KB Output is correct
16 Correct 39 ms 15932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 12616 KB Output is correct
2 Correct 0 ms 796 KB Output is correct
3 Correct 25 ms 12328 KB Output is correct
4 Correct 36 ms 14132 KB Output is correct
5 Correct 35 ms 14200 KB Output is correct
6 Correct 27 ms 12692 KB Output is correct
7 Correct 31 ms 12800 KB Output is correct
8 Correct 33 ms 13476 KB Output is correct
9 Correct 32 ms 13484 KB Output is correct
10 Correct 35 ms 13140 KB Output is correct
11 Correct 32 ms 13204 KB Output is correct
12 Correct 31 ms 13224 KB Output is correct
13 Correct 31 ms 13212 KB Output is correct
14 Correct 33 ms 13468 KB Output is correct
15 Correct 33 ms 13472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 12616 KB Output is correct
2 Correct 0 ms 796 KB Output is correct
3 Correct 25 ms 12328 KB Output is correct
4 Correct 36 ms 14132 KB Output is correct
5 Correct 35 ms 14200 KB Output is correct
6 Correct 27 ms 12692 KB Output is correct
7 Correct 31 ms 12800 KB Output is correct
8 Correct 33 ms 13476 KB Output is correct
9 Correct 32 ms 13484 KB Output is correct
10 Correct 35 ms 13140 KB Output is correct
11 Correct 32 ms 13204 KB Output is correct
12 Correct 31 ms 13224 KB Output is correct
13 Correct 31 ms 13212 KB Output is correct
14 Correct 33 ms 13468 KB Output is correct
15 Correct 33 ms 13472 KB Output is correct
16 Correct 26 ms 11316 KB Output is correct
17 Correct 28 ms 11576 KB Output is correct
18 Correct 27 ms 11268 KB Output is correct
19 Correct 27 ms 11144 KB Output is correct
20 Correct 32 ms 11856 KB Output is correct
21 Correct 28 ms 11592 KB Output is correct
22 Correct 31 ms 13604 KB Output is correct
23 Correct 26 ms 11396 KB Output is correct
24 Correct 27 ms 11388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1044 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 2 ms 1044 KB Output is correct
4 Correct 2 ms 1048 KB Output is correct
5 Correct 2 ms 1052 KB Output is correct
6 Correct 2 ms 1052 KB Output is correct
7 Correct 2 ms 1044 KB Output is correct
8 Correct 2 ms 1044 KB Output is correct
9 Correct 2 ms 1036 KB Output is correct
10 Correct 2 ms 1048 KB Output is correct
11 Correct 2 ms 1052 KB Output is correct
12 Correct 2 ms 1044 KB Output is correct
13 Correct 2 ms 1048 KB Output is correct
14 Correct 2 ms 1044 KB Output is correct
15 Correct 2 ms 1040 KB Output is correct
16 Correct 2 ms 1052 KB Output is correct
17 Correct 2 ms 1036 KB Output is correct
18 Correct 2 ms 1036 KB Output is correct
19 Correct 2 ms 1052 KB Output is correct
20 Correct 2 ms 1048 KB Output is correct
21 Correct 2 ms 1044 KB Output is correct
22 Correct 2 ms 1044 KB Output is correct
23 Correct 2 ms 1052 KB Output is correct
24 Correct 2 ms 1048 KB Output is correct
25 Correct 2 ms 1044 KB Output is correct
26 Correct 2 ms 1048 KB Output is correct
27 Correct 2 ms 1048 KB Output is correct
28 Correct 2 ms 1036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 10892 KB Output is correct
2 Correct 42 ms 11600 KB Output is correct
3 Correct 1 ms 788 KB Output is correct
4 Correct 23 ms 10616 KB Output is correct
5 Correct 30 ms 12172 KB Output is correct
6 Correct 31 ms 12068 KB Output is correct
7 Correct 34 ms 11624 KB Output is correct
8 Correct 27 ms 11136 KB Output is correct
9 Correct 31 ms 12232 KB Output is correct
10 Correct 32 ms 12160 KB Output is correct
11 Correct 48 ms 12140 KB Output is correct
12 Correct 35 ms 12196 KB Output is correct
13 Correct 31 ms 12084 KB Output is correct
14 Correct 34 ms 12156 KB Output is correct
15 Correct 38 ms 12164 KB Output is correct
16 Correct 31 ms 12156 KB Output is correct
17 Correct 30 ms 11908 KB Output is correct
18 Correct 32 ms 11900 KB Output is correct
19 Correct 32 ms 11916 KB Output is correct
20 Correct 33 ms 12148 KB Output is correct
21 Correct 32 ms 11756 KB Output is correct
22 Correct 36 ms 11912 KB Output is correct
23 Correct 32 ms 11180 KB Output is correct
24 Correct 30 ms 10920 KB Output is correct
25 Correct 27 ms 11108 KB Output is correct
26 Correct 30 ms 11208 KB Output is correct
27 Correct 28 ms 11952 KB Output is correct
28 Correct 36 ms 11864 KB Output is correct
29 Correct 30 ms 11924 KB Output is correct
30 Correct 30 ms 11936 KB Output is correct
31 Correct 25 ms 11036 KB Output is correct
32 Correct 26 ms 10928 KB Output is correct
33 Correct 26 ms 11176 KB Output is correct
34 Correct 28 ms 11172 KB Output is correct
35 Correct 28 ms 11672 KB Output is correct
36 Correct 35 ms 11680 KB Output is correct
37 Correct 28 ms 11688 KB Output is correct
38 Correct 30 ms 11688 KB Output is correct
39 Correct 28 ms 11696 KB Output is correct
40 Correct 28 ms 11680 KB Output is correct
41 Correct 31 ms 12144 KB Output is correct
42 Correct 30 ms 11988 KB Output is correct
43 Correct 31 ms 12076 KB Output is correct
44 Correct 32 ms 12160 KB Output is correct
45 Correct 33 ms 12068 KB Output is correct
46 Correct 32 ms 11896 KB Output is correct
47 Correct 30 ms 11636 KB Output is correct
48 Correct 30 ms 11648 KB Output is correct
49 Correct 27 ms 11652 KB Output is correct
50 Correct 30 ms 11640 KB Output is correct
51 Correct 27 ms 11136 KB Output is correct
52 Correct 28 ms 11212 KB Output is correct
53 Correct 25 ms 11244 KB Output is correct
54 Correct 27 ms 11132 KB Output is correct
55 Correct 26 ms 11124 KB Output is correct
56 Correct 27 ms 11140 KB Output is correct
57 Correct 28 ms 11380 KB Output is correct
58 Correct 26 ms 11300 KB Output is correct
59 Correct 27 ms 11104 KB Output is correct
60 Correct 28 ms 11132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 10912 KB Output is correct
2 Correct 32 ms 11680 KB Output is correct
3 Correct 2 ms 780 KB Output is correct
4 Correct 26 ms 11024 KB Output is correct
5 Correct 33 ms 12080 KB Output is correct
6 Correct 30 ms 12232 KB Output is correct
7 Correct 27 ms 11128 KB Output is correct
8 Correct 30 ms 11240 KB Output is correct
9 Correct 45 ms 12332 KB Output is correct
10 Correct 32 ms 12152 KB Output is correct
11 Correct 31 ms 12168 KB Output is correct
12 Correct 33 ms 12120 KB Output is correct
13 Correct 31 ms 11940 KB Output is correct
14 Correct 33 ms 12196 KB Output is correct
15 Correct 33 ms 12068 KB Output is correct
16 Correct 30 ms 12152 KB Output is correct
17 Correct 30 ms 11888 KB Output is correct
18 Correct 33 ms 11884 KB Output is correct
19 Correct 36 ms 11896 KB Output is correct
20 Correct 34 ms 12072 KB Output is correct
21 Correct 40 ms 11856 KB Output is correct
22 Correct 30 ms 11744 KB Output is correct
23 Correct 27 ms 10876 KB Output is correct
24 Correct 27 ms 10880 KB Output is correct
25 Correct 31 ms 11144 KB Output is correct
26 Correct 26 ms 11176 KB Output is correct
27 Correct 31 ms 11916 KB Output is correct
28 Correct 30 ms 11928 KB Output is correct
29 Correct 31 ms 12132 KB Output is correct
30 Correct 36 ms 11788 KB Output is correct
31 Correct 26 ms 10920 KB Output is correct
32 Correct 25 ms 10916 KB Output is correct
33 Correct 30 ms 11180 KB Output is correct
34 Correct 27 ms 11120 KB Output is correct
35 Correct 27 ms 11704 KB Output is correct
36 Correct 40 ms 11952 KB Output is correct
37 Correct 28 ms 11688 KB Output is correct
38 Correct 30 ms 11620 KB Output is correct
39 Correct 30 ms 11648 KB Output is correct
40 Correct 33 ms 11600 KB Output is correct
41 Correct 30 ms 11912 KB Output is correct
42 Correct 34 ms 12140 KB Output is correct
43 Correct 32 ms 11832 KB Output is correct
44 Correct 37 ms 12136 KB Output is correct
45 Correct 30 ms 11932 KB Output is correct
46 Correct 31 ms 12160 KB Output is correct
47 Correct 34 ms 11620 KB Output is correct
48 Correct 28 ms 11652 KB Output is correct
49 Correct 34 ms 11624 KB Output is correct
50 Correct 28 ms 11560 KB Output is correct
51 Correct 27 ms 11148 KB Output is correct
52 Correct 26 ms 11144 KB Output is correct
53 Correct 27 ms 11040 KB Output is correct
54 Correct 27 ms 11132 KB Output is correct
55 Correct 30 ms 11104 KB Output is correct
56 Correct 26 ms 11436 KB Output is correct
57 Correct 27 ms 11396 KB Output is correct
58 Correct 27 ms 11268 KB Output is correct
59 Correct 30 ms 11124 KB Output is correct
60 Correct 26 ms 11084 KB Output is correct