Submission #904169

# Submission time Handle Problem Language Result Execution time Memory
904169 2024-01-11T20:55:38 Z guechotjrhh Stray Cat (JOI20_stray) C++14
100 / 100
44 ms 16640 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;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 15752 KB Output is correct
2 Correct 1 ms 788 KB Output is correct
3 Correct 26 ms 15168 KB Output is correct
4 Correct 44 ms 16564 KB Output is correct
5 Correct 40 ms 16640 KB Output is correct
6 Correct 31 ms 15452 KB Output is correct
7 Correct 32 ms 15484 KB Output is correct
8 Correct 41 ms 16252 KB Output is correct
9 Correct 40 ms 16416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 15752 KB Output is correct
2 Correct 1 ms 788 KB Output is correct
3 Correct 26 ms 15168 KB Output is correct
4 Correct 44 ms 16564 KB Output is correct
5 Correct 40 ms 16640 KB Output is correct
6 Correct 31 ms 15452 KB Output is correct
7 Correct 32 ms 15484 KB Output is correct
8 Correct 41 ms 16252 KB Output is correct
9 Correct 40 ms 16416 KB Output is correct
10 Correct 27 ms 13624 KB Output is correct
11 Correct 32 ms 13640 KB Output is correct
12 Correct 27 ms 13604 KB Output is correct
13 Correct 28 ms 13560 KB Output is correct
14 Correct 28 ms 13756 KB Output is correct
15 Correct 33 ms 14188 KB Output is correct
16 Correct 40 ms 16168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13288 KB Output is correct
2 Correct 1 ms 796 KB Output is correct
3 Correct 28 ms 12772 KB Output is correct
4 Correct 40 ms 14608 KB Output is correct
5 Correct 36 ms 14520 KB Output is correct
6 Correct 31 ms 13128 KB Output is correct
7 Correct 28 ms 13184 KB Output is correct
8 Correct 37 ms 13964 KB Output is correct
9 Correct 33 ms 13924 KB Output is correct
10 Correct 32 ms 13632 KB Output is correct
11 Correct 34 ms 13708 KB Output is correct
12 Correct 31 ms 13704 KB Output is correct
13 Correct 31 ms 13936 KB Output is correct
14 Correct 42 ms 13944 KB Output is correct
15 Correct 36 ms 13960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13288 KB Output is correct
2 Correct 1 ms 796 KB Output is correct
3 Correct 28 ms 12772 KB Output is correct
4 Correct 40 ms 14608 KB Output is correct
5 Correct 36 ms 14520 KB Output is correct
6 Correct 31 ms 13128 KB Output is correct
7 Correct 28 ms 13184 KB Output is correct
8 Correct 37 ms 13964 KB Output is correct
9 Correct 33 ms 13924 KB Output is correct
10 Correct 32 ms 13632 KB Output is correct
11 Correct 34 ms 13708 KB Output is correct
12 Correct 31 ms 13704 KB Output is correct
13 Correct 31 ms 13936 KB Output is correct
14 Correct 42 ms 13944 KB Output is correct
15 Correct 36 ms 13960 KB Output is correct
16 Correct 31 ms 11780 KB Output is correct
17 Correct 24 ms 11592 KB Output is correct
18 Correct 26 ms 11604 KB Output is correct
19 Correct 26 ms 11860 KB Output is correct
20 Correct 30 ms 12384 KB Output is correct
21 Correct 27 ms 12104 KB Output is correct
22 Correct 33 ms 14204 KB Output is correct
23 Correct 28 ms 11868 KB Output is correct
24 Correct 27 ms 11852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1056 KB Output is correct
2 Correct 1 ms 1048 KB Output is correct
3 Correct 2 ms 1056 KB Output is correct
4 Correct 2 ms 1056 KB Output is correct
5 Correct 2 ms 1056 KB Output is correct
6 Correct 2 ms 1056 KB Output is correct
7 Correct 2 ms 1552 KB Output is correct
8 Correct 2 ms 1064 KB Output is correct
9 Correct 2 ms 1056 KB Output is correct
10 Correct 2 ms 1056 KB Output is correct
11 Correct 2 ms 1056 KB Output is correct
12 Correct 2 ms 1056 KB Output is correct
13 Correct 2 ms 1056 KB Output is correct
14 Correct 2 ms 1048 KB Output is correct
15 Correct 2 ms 1056 KB Output is correct
16 Correct 2 ms 1032 KB Output is correct
17 Correct 2 ms 1048 KB Output is correct
18 Correct 2 ms 1044 KB Output is correct
19 Correct 2 ms 1052 KB Output is correct
20 Correct 2 ms 1060 KB Output is correct
21 Correct 2 ms 1048 KB Output is correct
22 Correct 2 ms 1048 KB Output is correct
23 Correct 2 ms 1056 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 1056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 11236 KB Output is correct
2 Correct 28 ms 12148 KB Output is correct
3 Correct 2 ms 796 KB Output is correct
4 Correct 23 ms 11060 KB Output is correct
5 Correct 39 ms 12544 KB Output is correct
6 Correct 34 ms 12596 KB Output is correct
7 Correct 30 ms 11612 KB Output is correct
8 Correct 27 ms 11624 KB Output is correct
9 Correct 35 ms 12632 KB Output is correct
10 Correct 31 ms 12536 KB Output is correct
11 Correct 32 ms 12600 KB Output is correct
12 Correct 33 ms 12636 KB Output is correct
13 Correct 34 ms 12580 KB Output is correct
14 Correct 38 ms 12636 KB Output is correct
15 Correct 37 ms 12596 KB Output is correct
16 Correct 34 ms 12560 KB Output is correct
17 Correct 31 ms 12332 KB Output is correct
18 Correct 30 ms 12376 KB Output is correct
19 Correct 31 ms 12368 KB Output is correct
20 Correct 34 ms 12392 KB Output is correct
21 Correct 30 ms 12376 KB Output is correct
22 Correct 31 ms 12320 KB Output is correct
23 Correct 26 ms 11492 KB Output is correct
24 Correct 26 ms 11392 KB Output is correct
25 Correct 27 ms 11584 KB Output is correct
26 Correct 28 ms 11584 KB Output is correct
27 Correct 31 ms 12384 KB Output is correct
28 Correct 30 ms 12372 KB Output is correct
29 Correct 34 ms 12440 KB Output is correct
30 Correct 28 ms 12388 KB Output is correct
31 Correct 27 ms 11268 KB Output is correct
32 Correct 28 ms 11316 KB Output is correct
33 Correct 25 ms 11600 KB Output is correct
34 Correct 26 ms 11620 KB Output is correct
35 Correct 28 ms 12048 KB Output is correct
36 Correct 34 ms 12388 KB Output is correct
37 Correct 31 ms 12032 KB Output is correct
38 Correct 28 ms 12120 KB Output is correct
39 Correct 28 ms 12088 KB Output is correct
40 Correct 28 ms 12120 KB Output is correct
41 Correct 30 ms 12340 KB Output is correct
42 Correct 34 ms 12296 KB Output is correct
43 Correct 32 ms 12348 KB Output is correct
44 Correct 35 ms 12644 KB Output is correct
45 Correct 31 ms 12344 KB Output is correct
46 Correct 35 ms 12380 KB Output is correct
47 Correct 31 ms 12064 KB Output is correct
48 Correct 28 ms 12072 KB Output is correct
49 Correct 28 ms 11880 KB Output is correct
50 Correct 31 ms 12112 KB Output is correct
51 Correct 27 ms 11608 KB Output is correct
52 Correct 28 ms 11752 KB Output is correct
53 Correct 27 ms 11616 KB Output is correct
54 Correct 27 ms 11616 KB Output is correct
55 Correct 32 ms 11684 KB Output is correct
56 Correct 30 ms 11608 KB Output is correct
57 Correct 27 ms 11860 KB Output is correct
58 Correct 27 ms 11680 KB Output is correct
59 Correct 26 ms 11604 KB Output is correct
60 Correct 27 ms 11604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 11388 KB Output is correct
2 Correct 30 ms 12068 KB Output is correct
3 Correct 2 ms 1040 KB Output is correct
4 Correct 23 ms 11072 KB Output is correct
5 Correct 31 ms 12592 KB Output is correct
6 Correct 34 ms 12568 KB Output is correct
7 Correct 27 ms 11332 KB Output is correct
8 Correct 26 ms 11616 KB Output is correct
9 Correct 32 ms 12644 KB Output is correct
10 Correct 32 ms 12636 KB Output is correct
11 Correct 36 ms 12576 KB Output is correct
12 Correct 33 ms 12640 KB Output is correct
13 Correct 32 ms 12432 KB Output is correct
14 Correct 32 ms 12640 KB Output is correct
15 Correct 33 ms 12560 KB Output is correct
16 Correct 32 ms 12632 KB Output is correct
17 Correct 30 ms 12312 KB Output is correct
18 Correct 33 ms 12376 KB Output is correct
19 Correct 33 ms 12352 KB Output is correct
20 Correct 31 ms 12212 KB Output is correct
21 Correct 31 ms 12312 KB Output is correct
22 Correct 30 ms 12296 KB Output is correct
23 Correct 26 ms 11384 KB Output is correct
24 Correct 26 ms 11344 KB Output is correct
25 Correct 40 ms 11728 KB Output is correct
26 Correct 27 ms 11560 KB Output is correct
27 Correct 35 ms 12400 KB Output is correct
28 Correct 28 ms 12344 KB Output is correct
29 Correct 32 ms 12368 KB Output is correct
30 Correct 30 ms 12332 KB Output is correct
31 Correct 35 ms 11552 KB Output is correct
32 Correct 28 ms 11368 KB Output is correct
33 Correct 27 ms 11600 KB Output is correct
34 Correct 26 ms 11516 KB Output is correct
35 Correct 30 ms 12112 KB Output is correct
36 Correct 32 ms 12532 KB Output is correct
37 Correct 30 ms 12216 KB Output is correct
38 Correct 32 ms 12132 KB Output is correct
39 Correct 28 ms 12120 KB Output is correct
40 Correct 30 ms 12132 KB Output is correct
41 Correct 28 ms 12292 KB Output is correct
42 Correct 34 ms 12280 KB Output is correct
43 Correct 31 ms 12520 KB Output is correct
44 Correct 35 ms 12436 KB Output is correct
45 Correct 32 ms 12804 KB Output is correct
46 Correct 30 ms 12640 KB Output is correct
47 Correct 32 ms 12032 KB Output is correct
48 Correct 28 ms 12136 KB Output is correct
49 Correct 30 ms 12132 KB Output is correct
50 Correct 28 ms 12116 KB Output is correct
51 Correct 27 ms 11624 KB Output is correct
52 Correct 28 ms 11616 KB Output is correct
53 Correct 27 ms 11576 KB Output is correct
54 Correct 28 ms 11472 KB Output is correct
55 Correct 27 ms 11588 KB Output is correct
56 Correct 28 ms 11512 KB Output is correct
57 Correct 27 ms 11772 KB Output is correct
58 Correct 27 ms 11752 KB Output is correct
59 Correct 26 ms 11620 KB Output is correct
60 Correct 27 ms 11540 KB Output is correct