답안 #760661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760661 2023-06-18T05:22:51 Z Magikarp4000 길고양이 (JOI20_stray) C++17
100 / 100
37 ms 16872 KB
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n' 
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;

const int pat[] = {1,1,0,1,0,0};

const int MAXN = 2e4+1;
int n,m;
vector<PII> v[MAXN];
int p[MAXN], pr[MAXN];
vector<int> res;
int d[MAXN], a[MAXN];

namespace {
    void dfs(int s, int pa) {
        if (s != 0 && v[s].size() >= 3) {
            int c = res[pr[s]] == 1 ? 0 : 1;
            FORX(u,v[s]) {
                if (u.F == pa) continue;
                res[u.S] = c;
            }
            if (res[pr[s]] == -1) res[pr[s]] = 0;
        }
        FORX(u,v[s]) {
            if (u.F == pa) continue;
            pr[u.F] = s;
            pr[u.F] = u.S;
            dfs(u.F,s);
        }
    }

    void dfs1(int s, int pa, int idx) {
        FORX(u,v[s]) {
            if (u.F == pa) continue;
            int nc = idx;
            if ((s == 0 || v[s].size() == 2) && res[u.S] == -1) {
                res[u.S] = pat[idx];
                nc = (idx+1)%6;
            }
            if (v[s].size() >= 3) nc = 0;
            dfs1(u.F,s,nc);
        }
    }

    void dfs2(int s, int pa, int val) {
        FORX(u,v[s]) {
            if (u.F == pa) continue;
            res[u.S] = val;
            dfs2(u.F,s,(val+1)%3);
        }
    }
} // namespace

void sub4() {
    queue<PII> q;
    FOR(i,0,n) d[i] = INF;
    d[0] = 0;
    q.push({0,0});
    while (!q.empty()) {
        int s = q.front().F, val = q.front().S;
        q.pop();
        FORX(u,v[s]) {
            if (d[s]+1 < d[u.F]) {
                d[u.F] = d[s]+1;
                q.push({u.F,(val+1)%3});
            }
        }
    }
    FORX(u,v[0]) res[u.S] = 0;
    vector<PII> p;
    FOR(i,1,n) p.PB({d[i],i});
    sort(ALL(p));
    FOR(i,0,(int)p.size()) {
        FORX(u,v[p[i].S]) {
            if (res[u.S] == -1) {
                res[u.S] = p[i].F%3;
            }
        }
    }
}

void sub7() {
    dfs(0,-1);
    dfs1(0,-1,0);
}

std::vector<int> Mark(int N, int M, int A, int B, std::vector<int> U, std::vector<int> V) {
    n = N; m = M;
    FOR(i,0,m) {
        v[U[i]].PB({V[i],i});
        v[V[i]].PB({U[i],i});
    }
    FOR(i,0,m) res.PB(-1);
    if (A == 2) sub7();
    else sub4();
    return res;
}
#include "Catherine.h"
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n' 
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;

namespace {
    int A, B;
    bool flag = 0;
    PII start = {-1,-1}, turn = {0,0};
    bool done = 0;
    int pre = -1;

    int bruh(int x) {
        if (x != -1) pre = x;
        return x;
    }
} // namespace

void Init(int A, int B)
{
    ::A = A;
    ::B = B;
}

int sub7(std::vector<int> y) {
    int c0 = y[0], c1 = y[1];
    if (pre == 0) c0++;
    else if (pre == 1) c1++;
    if (c0+c1 == 1) {
        flag = 1;
        if (y[0]) return bruh(0);
        if (y[1]) return bruh(1);
        return bruh(-1);
    }
    if (c0+c1 >= 3) {
        flag = 1;
        if (c0 == 1) {
            if (y[0] == 1) return bruh(0);
            return bruh(-1);
        }
        else if (c1 == 1) {
            if (y[1] == 1) return bruh(1);
            return bruh(-1);
        }
    }
    if (flag) return y[0] == 1 ? bruh(0) : bruh(1);
    if (start == make_pair(-1,-1)) {
        start.F = (c0 == 2 || c1 == 2) ? 2 : 1;
        start.S = (c1 == 2) ? 1 : 0;
        turn.F++;
        pre = start.S;
        return bruh(start.S);
    }
    bool db = (c0 == 2 || c1 == 2) ? 1 : 0;
    int val = y[0] == 1 ? 0 : 1;
    if (start == make_pair(2,0)) {
        if (turn.F == 2) {
            flag = 1;
            return db ? bruh(-1) : bruh(val);
        }
        else {
            turn.F++;
            return bruh(val);
        }
    }
    else if (start == make_pair(2,1)) {
        if (turn.F == 2) {
            flag = 1;
            return db ? bruh(val) : bruh(-1);
        }
        else {
            turn.F++;
            return bruh(val);
        }
    }
    else {
        if (turn.F == 2) {
            flag = 1;
            return db ? bruh(val) : bruh(-1);
        }
        else if (turn.F == 1) {
            if (!done) {
                if (!db) {
                    turn.F++;
                    return bruh(val);
                }
                else {
                    done = 1;
                    turn.S++;
                    return bruh(-1);
                }
            }
            else {
                if (turn.S == 2) {
                    flag = 1;
                    return db ? bruh(-1) : bruh(val);
                }
                else {
                    turn.S++;
                    return bruh(val);
                }
            }
        }
    }
}

int sub4(std::vector<int> y) {
    int c[3] = {0,0,0};
    FOR(i,0,3) c[i] += y[i];
    if (pre != -1) c[pre]++;
    if (c[0] && c[1]) return bruh(0);
    if (c[1] && c[2]) return bruh(1);
    if (c[2] && c[0]) return bruh(2);
    FOR(i,0,3) if (c[i]) return bruh(i);
}

int Move(std::vector<int> y) {
    if (A == 2) return sub7(y);
    else return sub4(y);
}

Compilation message

Catherine.cpp: In function 'int sub7(std::vector<int>)':
Catherine.cpp:124:1: warning: control reaches end of non-void function [-Wreturn-type]
  124 | }
      | ^
Catherine.cpp: In function 'int sub4(std::vector<int>)':
Catherine.cpp:134:1: warning: control reaches end of non-void function [-Wreturn-type]
  134 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 15736 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 25 ms 15016 KB Output is correct
4 Correct 35 ms 16872 KB Output is correct
5 Correct 36 ms 16696 KB Output is correct
6 Correct 28 ms 15516 KB Output is correct
7 Correct 28 ms 15508 KB Output is correct
8 Correct 34 ms 16144 KB Output is correct
9 Correct 35 ms 16072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 15736 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 25 ms 15016 KB Output is correct
4 Correct 35 ms 16872 KB Output is correct
5 Correct 36 ms 16696 KB Output is correct
6 Correct 28 ms 15516 KB Output is correct
7 Correct 28 ms 15508 KB Output is correct
8 Correct 34 ms 16144 KB Output is correct
9 Correct 35 ms 16072 KB Output is correct
10 Correct 28 ms 13560 KB Output is correct
11 Correct 27 ms 13532 KB Output is correct
12 Correct 27 ms 13484 KB Output is correct
13 Correct 27 ms 13440 KB Output is correct
14 Correct 28 ms 13752 KB Output is correct
15 Correct 31 ms 14108 KB Output is correct
16 Correct 34 ms 16308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 13300 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 23 ms 12800 KB Output is correct
4 Correct 34 ms 14616 KB Output is correct
5 Correct 36 ms 14604 KB Output is correct
6 Correct 28 ms 13268 KB Output is correct
7 Correct 28 ms 13304 KB Output is correct
8 Correct 32 ms 13836 KB Output is correct
9 Correct 32 ms 13756 KB Output is correct
10 Correct 31 ms 13512 KB Output is correct
11 Correct 31 ms 13508 KB Output is correct
12 Correct 31 ms 13476 KB Output is correct
13 Correct 30 ms 13612 KB Output is correct
14 Correct 32 ms 13764 KB Output is correct
15 Correct 32 ms 13768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 13300 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 23 ms 12800 KB Output is correct
4 Correct 34 ms 14616 KB Output is correct
5 Correct 36 ms 14604 KB Output is correct
6 Correct 28 ms 13268 KB Output is correct
7 Correct 28 ms 13304 KB Output is correct
8 Correct 32 ms 13836 KB Output is correct
9 Correct 32 ms 13756 KB Output is correct
10 Correct 31 ms 13512 KB Output is correct
11 Correct 31 ms 13508 KB Output is correct
12 Correct 31 ms 13476 KB Output is correct
13 Correct 30 ms 13612 KB Output is correct
14 Correct 32 ms 13764 KB Output is correct
15 Correct 32 ms 13768 KB Output is correct
16 Correct 24 ms 12024 KB Output is correct
17 Correct 28 ms 12088 KB Output is correct
18 Correct 26 ms 12068 KB Output is correct
19 Correct 30 ms 12256 KB Output is correct
20 Correct 28 ms 12672 KB Output is correct
21 Correct 27 ms 12408 KB Output is correct
22 Correct 31 ms 14492 KB Output is correct
23 Correct 26 ms 12176 KB Output is correct
24 Correct 30 ms 12204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1380 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 2 ms 1292 KB Output is correct
4 Correct 2 ms 1420 KB Output is correct
5 Correct 2 ms 1292 KB Output is correct
6 Correct 2 ms 1412 KB Output is correct
7 Correct 2 ms 1416 KB Output is correct
8 Correct 2 ms 1420 KB Output is correct
9 Correct 2 ms 1344 KB Output is correct
10 Correct 2 ms 1284 KB Output is correct
11 Correct 1 ms 1292 KB Output is correct
12 Correct 2 ms 1292 KB Output is correct
13 Correct 2 ms 1292 KB Output is correct
14 Correct 1 ms 1412 KB Output is correct
15 Correct 2 ms 1280 KB Output is correct
16 Correct 1 ms 1292 KB Output is correct
17 Correct 1 ms 1292 KB Output is correct
18 Correct 2 ms 1292 KB Output is correct
19 Correct 2 ms 1292 KB Output is correct
20 Correct 2 ms 1288 KB Output is correct
21 Correct 1 ms 1284 KB Output is correct
22 Correct 2 ms 1284 KB Output is correct
23 Correct 1 ms 1284 KB Output is correct
24 Correct 2 ms 1284 KB Output is correct
25 Correct 1 ms 1288 KB Output is correct
26 Correct 2 ms 1284 KB Output is correct
27 Correct 2 ms 1292 KB Output is correct
28 Correct 1 ms 1304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11108 KB Output is correct
2 Correct 32 ms 12400 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 20 ms 11248 KB Output is correct
5 Correct 31 ms 14040 KB Output is correct
6 Correct 31 ms 14108 KB Output is correct
7 Correct 26 ms 13188 KB Output is correct
8 Correct 26 ms 13156 KB Output is correct
9 Correct 31 ms 14000 KB Output is correct
10 Correct 31 ms 13996 KB Output is correct
11 Correct 31 ms 14052 KB Output is correct
12 Correct 31 ms 14068 KB Output is correct
13 Correct 35 ms 13816 KB Output is correct
14 Correct 30 ms 14012 KB Output is correct
15 Correct 32 ms 13980 KB Output is correct
16 Correct 31 ms 14020 KB Output is correct
17 Correct 30 ms 13808 KB Output is correct
18 Correct 28 ms 13796 KB Output is correct
19 Correct 30 ms 13640 KB Output is correct
20 Correct 28 ms 13732 KB Output is correct
21 Correct 28 ms 13732 KB Output is correct
22 Correct 33 ms 13756 KB Output is correct
23 Correct 25 ms 11224 KB Output is correct
24 Correct 25 ms 11236 KB Output is correct
25 Correct 26 ms 11748 KB Output is correct
26 Correct 28 ms 11592 KB Output is correct
27 Correct 27 ms 12436 KB Output is correct
28 Correct 27 ms 12520 KB Output is correct
29 Correct 27 ms 12540 KB Output is correct
30 Correct 27 ms 12512 KB Output is correct
31 Correct 25 ms 11200 KB Output is correct
32 Correct 24 ms 11136 KB Output is correct
33 Correct 25 ms 11764 KB Output is correct
34 Correct 24 ms 11752 KB Output is correct
35 Correct 27 ms 12536 KB Output is correct
36 Correct 32 ms 12440 KB Output is correct
37 Correct 28 ms 12416 KB Output is correct
38 Correct 27 ms 12480 KB Output is correct
39 Correct 28 ms 12444 KB Output is correct
40 Correct 27 ms 12548 KB Output is correct
41 Correct 28 ms 13108 KB Output is correct
42 Correct 28 ms 13148 KB Output is correct
43 Correct 28 ms 13048 KB Output is correct
44 Correct 31 ms 12976 KB Output is correct
45 Correct 28 ms 13044 KB Output is correct
46 Correct 28 ms 13080 KB Output is correct
47 Correct 27 ms 12308 KB Output is correct
48 Correct 27 ms 12216 KB Output is correct
49 Correct 27 ms 12140 KB Output is correct
50 Correct 31 ms 12264 KB Output is correct
51 Correct 25 ms 11188 KB Output is correct
52 Correct 24 ms 11216 KB Output is correct
53 Correct 26 ms 11244 KB Output is correct
54 Correct 25 ms 11248 KB Output is correct
55 Correct 25 ms 11240 KB Output is correct
56 Correct 24 ms 11268 KB Output is correct
57 Correct 28 ms 11372 KB Output is correct
58 Correct 27 ms 11252 KB Output is correct
59 Correct 25 ms 11348 KB Output is correct
60 Correct 25 ms 11336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11108 KB Output is correct
2 Correct 27 ms 12240 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 22 ms 11252 KB Output is correct
5 Correct 31 ms 14052 KB Output is correct
6 Correct 37 ms 13964 KB Output is correct
7 Correct 26 ms 13160 KB Output is correct
8 Correct 26 ms 13136 KB Output is correct
9 Correct 31 ms 14112 KB Output is correct
10 Correct 31 ms 13920 KB Output is correct
11 Correct 31 ms 14016 KB Output is correct
12 Correct 31 ms 13936 KB Output is correct
13 Correct 31 ms 13984 KB Output is correct
14 Correct 31 ms 14048 KB Output is correct
15 Correct 30 ms 13976 KB Output is correct
16 Correct 35 ms 13944 KB Output is correct
17 Correct 28 ms 13664 KB Output is correct
18 Correct 28 ms 13668 KB Output is correct
19 Correct 28 ms 13812 KB Output is correct
20 Correct 28 ms 13744 KB Output is correct
21 Correct 28 ms 13796 KB Output is correct
22 Correct 28 ms 13748 KB Output is correct
23 Correct 25 ms 11348 KB Output is correct
24 Correct 24 ms 11224 KB Output is correct
25 Correct 25 ms 11692 KB Output is correct
26 Correct 26 ms 11748 KB Output is correct
27 Correct 27 ms 12520 KB Output is correct
28 Correct 27 ms 12548 KB Output is correct
29 Correct 27 ms 12528 KB Output is correct
30 Correct 28 ms 12512 KB Output is correct
31 Correct 24 ms 11232 KB Output is correct
32 Correct 24 ms 11212 KB Output is correct
33 Correct 25 ms 11752 KB Output is correct
34 Correct 25 ms 11676 KB Output is correct
35 Correct 32 ms 12304 KB Output is correct
36 Correct 27 ms 12472 KB Output is correct
37 Correct 27 ms 12504 KB Output is correct
38 Correct 27 ms 12452 KB Output is correct
39 Correct 28 ms 12488 KB Output is correct
40 Correct 27 ms 12412 KB Output is correct
41 Correct 28 ms 13048 KB Output is correct
42 Correct 28 ms 13048 KB Output is correct
43 Correct 28 ms 13040 KB Output is correct
44 Correct 28 ms 13036 KB Output is correct
45 Correct 32 ms 13052 KB Output is correct
46 Correct 28 ms 13036 KB Output is correct
47 Correct 27 ms 12284 KB Output is correct
48 Correct 27 ms 12276 KB Output is correct
49 Correct 26 ms 12140 KB Output is correct
50 Correct 27 ms 12376 KB Output is correct
51 Correct 24 ms 11248 KB Output is correct
52 Correct 25 ms 11148 KB Output is correct
53 Correct 24 ms 11164 KB Output is correct
54 Correct 25 ms 11244 KB Output is correct
55 Correct 26 ms 11264 KB Output is correct
56 Correct 25 ms 11248 KB Output is correct
57 Correct 25 ms 11264 KB Output is correct
58 Correct 25 ms 11284 KB Output is correct
59 Correct 25 ms 11452 KB Output is correct
60 Correct 25 ms 11496 KB Output is correct