답안 #1063520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063520 2024-08-17T19:50:25 Z Andrey 길고양이 (JOI20_stray) C++14
100 / 100
39 ms 21636 KB
#include "Anthony.h"
#include<bits/stdc++.h>
using namespace std;
 
vector<pair<int,int>> haha[200001];
vector<int> dp(200001,-1);
vector<int> troll(0);
int bruhseq[6] = {0,1,0,0,1,1};
 
void dfs(int a, int t, int d, pair<int,int> usl) {
    int br = 0,x = -1;
    for(pair<int,int> v: haha[a]) {
        if(v.first != t) {
            br++;
        }
    }
    int p;
    if(br != 1) {
        usl = {d,d%2};   
    }
    else {
        for(int i = 0; i < 6; i++) {
            if((usl.first == -1 || bruhseq[(i+(d-usl.first))%6]%2 == usl.second)) {
                p = i;
                break;
            }
        }
    }
    for(pair<int,int> v: haha[a]) {
        if(v.first != t) {
            if(br == 1 && haha[v.first].size() != 2) {
                if(bruhseq[p]%2 != d%2) {
                    dfs(v.first,a,d+2,usl);
                }
                else {
                    dfs(v.first,a,d+1,usl);
                }
            }
            else {
                dfs(v.first,a,d+1,usl);
            }
            x = dp[v.first];
        }
    }
    if(br == 1) {
        if(x == -1) {
            x = p-1;
        }
        x++;
        dp[a] = x;
        for(auto v: haha[a]) {
            if(v.first != t) {
                troll[v.second] = bruhseq[x%6];
            }
        }
    }
    else {
        for(pair<int,int> v: haha[a]) {
            if(v.first != t) {
                troll[v.second] = d%2;
            }
        }
    }
}
 
std::vector<int> Mark(int n, int m, int a, int b, std::vector<int> u, std::vector<int> v) {
    for(int i = 0; i < m; i++) {
        haha[u[i]].push_back({v[i],i});
        haha[v[i]].push_back({u[i],i});
    }
    if(a > 2) {
        vector<int> br(n,INT_MAX);
        br[0] = 0;
        queue<int> idk;
        idk.push(0);
        vector<int> ans(m,-1);
        while(!idk.empty()) {
            int u = idk.front();
            idk.pop();
            for(pair<int,int> v: haha[u]) {
                if(br[v.first] == INT_MAX) {
                    br[v.first] = br[u]+1;
                    idk.push(v.first);
                }
            }
        }
        for(int i = 0; i < m; i++) {
            if(ans[i] == -1) {
                int c = min(br[u[i]],br[v[i]])%3;
                ans[i] = c;
            }
        }
        return ans;
    }
    else {
        troll.resize(n-1);
        dfs(0,-1,1,{-1,-1});
        /*for(int i = 0; i < troll.size(); i++) {
            cout << troll[i] << " ";
        }
        cout << endl;*/
        return troll;
    }
}
#include "Catherine.h"
#include<bits/stdc++.h>
using namespace std;
 
int A;
int seq[6] = {0,1,0,0,1,1};
vector<int> wow(0);
bool first = true;
bool yeah = true;
 
void Init(int a, int b) {
    A = a;
}
 
int Move(vector<int> haha) {
    if(A > 2) {
        vector<int> wow(0);
        for(int i = 0; i < haha.size(); i++) {
            if(haha[i] >= 1) {
                wow.push_back(i);
            }
        }
        if(wow.size() == 1) {
            return wow[0];
        }
        else if(wow.size() == 2) {
            if(wow[0] == 0 && wow[1] == 1) {
                return 0;
            }
            else if(wow[0] == 1 && wow[1] == 2) {
                return 1;
            }
            else {
                return 2;
            }
        }
    }
    else {
        if(first) {
            first = false;
            if(haha[0]+haha[1] == 2) {
                if(haha[0] == 2) {
                    wow.push_back(0);
                    wow.push_back(0);
                    return 0;
                }
                else if(haha[1] == 2) {
                    wow.push_back(1);
                    wow.push_back(1);
                    return 1;
                }
                else {
                    wow.push_back(1);
                    wow.push_back(0);
                    return 0;
                }
            }
            else {
                yeah = false;
                if(haha[0] == 1) {
                    wow.push_back(0);
                    return 0;
                }
                else {
                    wow.push_back(1);
                    return 1;
                }
            }
        }
        else {
            if(yeah) {
                if(haha[0]+haha[1] == 0) {
                    yeah = false;
                    return -1;
                }
                else if(haha[0]+haha[1] > 1) {
                    yeah = false;
                    if(haha[0] == 0 || haha[1] == 0) {
                        return -1;
                    }
                    else {
                        if(wow[wow.size()-1] == 1) {
                            wow.push_back(0);
                            return 0;
                        }
                        else {
                            wow.push_back(1);
                            return 1;
                        }
                    }
                }
                else if(wow.size() == 4) {
                    if(haha[0] > 0) {
                        wow.push_back(0);
                    }
                    else {
                        wow.push_back(1);
                    }
                    for(int i = 0; i < 6; i++) {
                        bool bubu = true;
                        for(int j = i; j < i+5; j++) {
                            if(wow[j-i] != seq[j%6]) {
                                bubu = false;
                            }
                        }
                        if(bubu) {
                            yeah = false;
                            break;
                        }
                    }
                    if(yeah) {
                        yeah = false;
                        return -1;
                    }
                    else {
                        if(haha[0] > 0) {
                            wow.push_back(0);
                            return 0;
                        }
                        else {
                            wow.push_back(1);
                            return 1;
                        }
                    }
                }
                else {
                    if(haha[0] > 0) {
                        wow.push_back(0);
                        return 0;
                    }
                    else {
                        wow.push_back(1);
                        return 1;
                    }
                }
            }
            else {
                if(haha[0]+haha[1] == 0) {
                    return 1/0;
                }
                if(haha[1] > 0 && (haha[0] == 0 || wow[wow.size()-1] == 0)) {
                    wow.push_back(1);
                    return 1;
                }
                else {
                    wow.push_back(0);
                    return 0;
                }
            }
        }
    }
}

Compilation message

Anthony.cpp: In function 'void dfs(int, int, int, std::pair<int, int>)':
Anthony.cpp:32:29: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |                 if(bruhseq[p]%2 != d%2) {
      |                    ~~~~~~~~~^

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:18:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         for(int i = 0; i < haha.size(); i++) {
      |                        ~~^~~~~~~~~~~~~
Catherine.cpp:139:29: warning: division by zero [-Wdiv-by-zero]
  139 |                     return 1/0;
      |                            ~^~
Catherine.cpp:152:1: warning: control reaches end of non-void function [-Wreturn-type]
  152 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 20524 KB Output is correct
2 Correct 2 ms 6176 KB Output is correct
3 Correct 22 ms 20104 KB Output is correct
4 Correct 38 ms 21636 KB Output is correct
5 Correct 35 ms 21628 KB Output is correct
6 Correct 25 ms 20280 KB Output is correct
7 Correct 25 ms 20332 KB Output is correct
8 Correct 28 ms 20976 KB Output is correct
9 Correct 30 ms 21124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 20524 KB Output is correct
2 Correct 2 ms 6176 KB Output is correct
3 Correct 22 ms 20104 KB Output is correct
4 Correct 38 ms 21636 KB Output is correct
5 Correct 35 ms 21628 KB Output is correct
6 Correct 25 ms 20280 KB Output is correct
7 Correct 25 ms 20332 KB Output is correct
8 Correct 28 ms 20976 KB Output is correct
9 Correct 30 ms 21124 KB Output is correct
10 Correct 25 ms 18536 KB Output is correct
11 Correct 25 ms 18364 KB Output is correct
12 Correct 33 ms 18552 KB Output is correct
13 Correct 23 ms 18560 KB Output is correct
14 Correct 24 ms 18824 KB Output is correct
15 Correct 26 ms 19068 KB Output is correct
16 Correct 31 ms 21188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 18056 KB Output is correct
2 Correct 2 ms 6176 KB Output is correct
3 Correct 24 ms 17780 KB Output is correct
4 Correct 32 ms 19584 KB Output is correct
5 Correct 32 ms 19432 KB Output is correct
6 Correct 25 ms 18056 KB Output is correct
7 Correct 24 ms 18224 KB Output is correct
8 Correct 30 ms 18804 KB Output is correct
9 Correct 30 ms 18824 KB Output is correct
10 Correct 26 ms 18596 KB Output is correct
11 Correct 33 ms 18464 KB Output is correct
12 Correct 28 ms 18556 KB Output is correct
13 Correct 26 ms 18560 KB Output is correct
14 Correct 30 ms 18932 KB Output is correct
15 Correct 39 ms 18812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 18056 KB Output is correct
2 Correct 2 ms 6176 KB Output is correct
3 Correct 24 ms 17780 KB Output is correct
4 Correct 32 ms 19584 KB Output is correct
5 Correct 32 ms 19432 KB Output is correct
6 Correct 25 ms 18056 KB Output is correct
7 Correct 24 ms 18224 KB Output is correct
8 Correct 30 ms 18804 KB Output is correct
9 Correct 30 ms 18824 KB Output is correct
10 Correct 26 ms 18596 KB Output is correct
11 Correct 33 ms 18464 KB Output is correct
12 Correct 28 ms 18556 KB Output is correct
13 Correct 26 ms 18560 KB Output is correct
14 Correct 30 ms 18932 KB Output is correct
15 Correct 39 ms 18812 KB Output is correct
16 Correct 22 ms 16500 KB Output is correct
17 Correct 23 ms 16596 KB Output is correct
18 Correct 24 ms 17008 KB Output is correct
19 Correct 24 ms 16508 KB Output is correct
20 Correct 26 ms 17204 KB Output is correct
21 Correct 27 ms 17016 KB Output is correct
22 Correct 27 ms 19080 KB Output is correct
23 Correct 23 ms 16760 KB Output is correct
24 Correct 31 ms 16816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6436 KB Output is correct
2 Correct 1 ms 6176 KB Output is correct
3 Correct 1 ms 6436 KB Output is correct
4 Correct 2 ms 6696 KB Output is correct
5 Correct 3 ms 6704 KB Output is correct
6 Correct 2 ms 6692 KB Output is correct
7 Correct 1 ms 6700 KB Output is correct
8 Correct 2 ms 6692 KB Output is correct
9 Correct 2 ms 6704 KB Output is correct
10 Correct 2 ms 6700 KB Output is correct
11 Correct 2 ms 6704 KB Output is correct
12 Correct 3 ms 6700 KB Output is correct
13 Correct 2 ms 6704 KB Output is correct
14 Correct 1 ms 6696 KB Output is correct
15 Correct 2 ms 6700 KB Output is correct
16 Correct 2 ms 6444 KB Output is correct
17 Correct 2 ms 6700 KB Output is correct
18 Correct 2 ms 6704 KB Output is correct
19 Correct 1 ms 6700 KB Output is correct
20 Correct 3 ms 6700 KB Output is correct
21 Correct 3 ms 6684 KB Output is correct
22 Correct 3 ms 6700 KB Output is correct
23 Correct 2 ms 6440 KB Output is correct
24 Correct 3 ms 6704 KB Output is correct
25 Correct 1 ms 6684 KB Output is correct
26 Correct 2 ms 6700 KB Output is correct
27 Correct 3 ms 6700 KB Output is correct
28 Correct 3 ms 6696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 16592 KB Output is correct
2 Correct 27 ms 17928 KB Output is correct
3 Correct 1 ms 6428 KB Output is correct
4 Correct 19 ms 16344 KB Output is correct
5 Correct 32 ms 20104 KB Output is correct
6 Correct 30 ms 20108 KB Output is correct
7 Correct 26 ms 19072 KB Output is correct
8 Correct 31 ms 18992 KB Output is correct
9 Correct 31 ms 19940 KB Output is correct
10 Correct 28 ms 20088 KB Output is correct
11 Correct 31 ms 20112 KB Output is correct
12 Correct 35 ms 20120 KB Output is correct
13 Correct 36 ms 20108 KB Output is correct
14 Correct 27 ms 20048 KB Output is correct
15 Correct 28 ms 20092 KB Output is correct
16 Correct 37 ms 20048 KB Output is correct
17 Correct 30 ms 19832 KB Output is correct
18 Correct 31 ms 19848 KB Output is correct
19 Correct 28 ms 19700 KB Output is correct
20 Correct 32 ms 19844 KB Output is correct
21 Correct 28 ms 19816 KB Output is correct
22 Correct 28 ms 19856 KB Output is correct
23 Correct 24 ms 16480 KB Output is correct
24 Correct 23 ms 16520 KB Output is correct
25 Correct 26 ms 17016 KB Output is correct
26 Correct 23 ms 17036 KB Output is correct
27 Correct 27 ms 18312 KB Output is correct
28 Correct 27 ms 18276 KB Output is correct
29 Correct 25 ms 18312 KB Output is correct
30 Correct 27 ms 18316 KB Output is correct
31 Correct 24 ms 16576 KB Output is correct
32 Correct 25 ms 16496 KB Output is correct
33 Correct 26 ms 17028 KB Output is correct
34 Correct 31 ms 17052 KB Output is correct
35 Correct 25 ms 18056 KB Output is correct
36 Correct 28 ms 18052 KB Output is correct
37 Correct 27 ms 18056 KB Output is correct
38 Correct 28 ms 18052 KB Output is correct
39 Correct 31 ms 18044 KB Output is correct
40 Correct 30 ms 18068 KB Output is correct
41 Correct 28 ms 18916 KB Output is correct
42 Correct 27 ms 18808 KB Output is correct
43 Correct 31 ms 18836 KB Output is correct
44 Correct 30 ms 19080 KB Output is correct
45 Correct 31 ms 19188 KB Output is correct
46 Correct 27 ms 19076 KB Output is correct
47 Correct 27 ms 17832 KB Output is correct
48 Correct 25 ms 17796 KB Output is correct
49 Correct 27 ms 17624 KB Output is correct
50 Correct 32 ms 17792 KB Output is correct
51 Correct 26 ms 16516 KB Output is correct
52 Correct 23 ms 16508 KB Output is correct
53 Correct 26 ms 16704 KB Output is correct
54 Correct 26 ms 16488 KB Output is correct
55 Correct 26 ms 16612 KB Output is correct
56 Correct 23 ms 16528 KB Output is correct
57 Correct 25 ms 16504 KB Output is correct
58 Correct 23 ms 16764 KB Output is correct
59 Correct 23 ms 16520 KB Output is correct
60 Correct 23 ms 16604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 16520 KB Output is correct
2 Correct 27 ms 17804 KB Output is correct
3 Correct 1 ms 6172 KB Output is correct
4 Correct 22 ms 16276 KB Output is correct
5 Correct 31 ms 20104 KB Output is correct
6 Correct 28 ms 20120 KB Output is correct
7 Correct 25 ms 19076 KB Output is correct
8 Correct 25 ms 19068 KB Output is correct
9 Correct 33 ms 19980 KB Output is correct
10 Correct 28 ms 20108 KB Output is correct
11 Correct 31 ms 20104 KB Output is correct
12 Correct 28 ms 20116 KB Output is correct
13 Correct 31 ms 20108 KB Output is correct
14 Correct 30 ms 20100 KB Output is correct
15 Correct 32 ms 20184 KB Output is correct
16 Correct 33 ms 19992 KB Output is correct
17 Correct 28 ms 19848 KB Output is correct
18 Correct 29 ms 19836 KB Output is correct
19 Correct 27 ms 19780 KB Output is correct
20 Correct 27 ms 19856 KB Output is correct
21 Correct 27 ms 19872 KB Output is correct
22 Correct 30 ms 19836 KB Output is correct
23 Correct 24 ms 16768 KB Output is correct
24 Correct 23 ms 16768 KB Output is correct
25 Correct 30 ms 17276 KB Output is correct
26 Correct 25 ms 17036 KB Output is correct
27 Correct 28 ms 18096 KB Output is correct
28 Correct 27 ms 18500 KB Output is correct
29 Correct 28 ms 18312 KB Output is correct
30 Correct 28 ms 18164 KB Output is correct
31 Correct 25 ms 16520 KB Output is correct
32 Correct 23 ms 16516 KB Output is correct
33 Correct 25 ms 17080 KB Output is correct
34 Correct 27 ms 17032 KB Output is correct
35 Correct 28 ms 18016 KB Output is correct
36 Correct 30 ms 18140 KB Output is correct
37 Correct 27 ms 18036 KB Output is correct
38 Correct 26 ms 18052 KB Output is correct
39 Correct 27 ms 18056 KB Output is correct
40 Correct 28 ms 18036 KB Output is correct
41 Correct 30 ms 18816 KB Output is correct
42 Correct 27 ms 18816 KB Output is correct
43 Correct 28 ms 18824 KB Output is correct
44 Correct 28 ms 19080 KB Output is correct
45 Correct 27 ms 19080 KB Output is correct
46 Correct 28 ms 19084 KB Output is correct
47 Correct 32 ms 18052 KB Output is correct
48 Correct 31 ms 17796 KB Output is correct
49 Correct 28 ms 17776 KB Output is correct
50 Correct 30 ms 17880 KB Output is correct
51 Correct 26 ms 16528 KB Output is correct
52 Correct 24 ms 16508 KB Output is correct
53 Correct 30 ms 16532 KB Output is correct
54 Correct 23 ms 16520 KB Output is correct
55 Correct 26 ms 16584 KB Output is correct
56 Correct 26 ms 16524 KB Output is correct
57 Correct 25 ms 16396 KB Output is correct
58 Correct 26 ms 16516 KB Output is correct
59 Correct 25 ms 16512 KB Output is correct
60 Correct 25 ms 16888 KB Output is correct