답안 #314768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314768 2020-10-21T06:55:11 Z georgerapeanu 길고양이 (JOI20_stray) C++14
100 / 100
71 ms 17372 KB
//#include "Anthony.h"
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdio>

using namespace std;

const int NMAX = 20000;

int viz[NMAX + 5];
vector<pair<int,int> > graph[NMAX + 5];
int a,b;
vector<int> secv = {0,1,0,0,1,1};
vector<int> ans;
int dist[NMAX + 5];

void dfs(int nod,int tata,int ind){
    queue<pair<pair<int,int>,int> > q;
    q.push({{nod,tata},ind});
    viz[nod] = true;
    while(!q.empty()){
        pair<pair<int,int>,int> tmp = q.front();
        q.pop();
        int nod = tmp.first.first;
        int tata = tmp.first.second;
        int ind = tmp.second;
        for(auto it:graph[nod]){
            if(it.first == tata){
                continue;
            }
            if(viz[it.first]){
                if(dist[it.first] < dist[nod]){
                    ans[it.second] = ind;
                }
                else{
                    ans[it.second] = (ind + 1) % 3;
                }
            }
            else{
                if(a == 3){
                    ans[it.second] = (ind + 1) % 3;
                    viz[it.first] = true;
                    dist[it.first] = 1 + dist[nod];
                    q.push({{it.first,nod},(ind + 1) % 3});
                }
                else{
                    ans[it.second] = secv[ind];
                    viz[it.first] = true;
                    dist[it.first] = 1 + dist[nod];
                    q.push({{it.first,nod},(graph[it.first].size() == 2 ? ((ind + 1) % 6):(1 - secv[ind]))});
                }
            }
        }
    }
}

vector<int> Mark(int N, int M, int A, int B,vector<int> U, vector<int> V) {
    
    a = min(3,A);
    b = B;

    ans = vector<int>(M,1);

    for(int i = 0;i < M;i++){
        graph[U[i]].push_back({V[i],i});
        graph[V[i]].push_back({U[i],i});
    }

    dfs(0,-1,0);
    
    //for(int i = 0;i < M;i++)printf("%d %d %d\n",U[i],V[i],ans[i]);printf("\n");

    return ans;
}
#include "Catherine.h"
//#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int _a,_b;

void Init(int A, int B) {
    _a = min(A,3);
    _b = B;
}

int lst = -1;
bool found_direction = false;

vector<vector<int> > good_secvs = 
{
    {0,1,0,0,1},
    {1,0,0,1,1},
    {0,0,1,1,0},
    {0,1,1,0,1},
    {1,1,0,1,0},
    {1,0,1,0,0}
};

vector<int> curr_secv;

int Move(vector<int> y) {
    if(_a == 3){
        if(y[0] == 0){
            if(y[1] == 0){
                return 2;
            }
            else{
                return 1;
            }
        }
        else if(y[1] == 0){
            if(y[2] == 0){
                return 0;
            }
            else{
                return 2;
            }
        }
        else{
            if(y[0] == 0){
                return 1;
            }
            else{
                return 0;
            }
        }
    }
   // printf("%d %d\n",y[0],y[1]);
    
    if(found_direction){
        if(y[0] == 0){
        //    printf("deb1 %d\n",1);
            return lst = 1;
        }
        if(y[1] == 0){
     //       printf("deb1 %d\n",0);
            return lst = 0;   
        }

        if(y[1] != 1){
       //     printf("deb1 %d\n",0);
            return lst = 0;
        }

        if(y[0] != 1){
         //   printf("deb1 %d\n",1);
            return lst = 1;
        }

        //printf("deb1 %d\n",1 - lst);
        return lst = 1 - lst;
    }

    if((lst != -1) + y[0] + y[1] == 1){
        found_direction = true;
        if(lst != -1){
          //  printf("deb1.5 %d\n",-1);
            return -1;
        }
       // printf("deb2 %d\n",(y[0] == 1 ? 0:1));
        return lst = (y[0] == 1 ? 0:1);
    }

    if(y[0] + y[1] + (lst != -1) > 2){
        found_direction = true;
        if(y[0] == 0){
            if(lst == -1){
         //       printf("deb3 %d\n",1);
                return lst = 1;
            }
            else{
         //       printf("deb4 %d\n",-1);
                return -1;
            }
        }
        if(y[1] == 0){
            if(lst == -1){
         //       printf("deb5 %d\n",0);
                return lst = 0;
            }
            else{
         //       printf("deb6 %d\n",-1);
                return -1;
            }
        }
       // printf("deb7 %d\n",(((lst == 0) + y[0]) < ((lst == 1) + y[1]) ? 0:1));
        return lst = (((lst == 0) + y[0]) < ((lst == 1) + y[1]) ? 0:1);
    }

    if(lst == -1){
        if(y[0] == 2){
            lst = 0;
            curr_secv.push_back(0);
            curr_secv.push_back(0);
         //   printf("deb8 %d\n",0);
            return 0;
        }
        else if(y[0] == 1){
            lst = 0;
            curr_secv.push_back(1);
            curr_secv.push_back(0);
         //   printf("deb9 %d\n",0);
            return 0;
        }
        else{
            lst = 1;
            curr_secv.push_back(1);
            curr_secv.push_back(1);
         //   printf("deb10 %d\n",1);
            return 1;
        }
    }
    else{
        if(y[0] == 1){
            curr_secv.push_back(lst = 0);
        }
        else{
            curr_secv.push_back(lst = 1);
        }
        if(curr_secv.size() == 5){
            bool found = false;
            for(auto it:good_secvs){
                bool tmp = true;
                for(int i = 0;i < 5;i++){
                    tmp &= (it[i] == curr_secv[i]);
                }
                if(tmp){
                    found = true;
                    break;
                }
            }
            if(found == true){
                found_direction = true;
           //     printf("deb11 %d\n",-1);
                return -1;
            }
            else{
                found_direction = true;
           //     printf("deb12 %d\n",lst);
                return lst;
            }
        }
        else{
          //  printf("deb13 %d\n",lst);
            return lst;
        }
    }

    //printf("wtf\n");
    return -10;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 15736 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 46 ms 15652 KB Output is correct
4 Correct 67 ms 17244 KB Output is correct
5 Correct 71 ms 17372 KB Output is correct
6 Correct 53 ms 15984 KB Output is correct
7 Correct 50 ms 15988 KB Output is correct
8 Correct 61 ms 16800 KB Output is correct
9 Correct 63 ms 16800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 15736 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 46 ms 15652 KB Output is correct
4 Correct 67 ms 17244 KB Output is correct
5 Correct 71 ms 17372 KB Output is correct
6 Correct 53 ms 15984 KB Output is correct
7 Correct 50 ms 15988 KB Output is correct
8 Correct 61 ms 16800 KB Output is correct
9 Correct 63 ms 16800 KB Output is correct
10 Correct 47 ms 14180 KB Output is correct
11 Correct 46 ms 14024 KB Output is correct
12 Correct 47 ms 14156 KB Output is correct
13 Correct 45 ms 14148 KB Output is correct
14 Correct 47 ms 14284 KB Output is correct
15 Correct 56 ms 14660 KB Output is correct
16 Correct 63 ms 16720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 13308 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 44 ms 13164 KB Output is correct
4 Correct 65 ms 14588 KB Output is correct
5 Correct 64 ms 14808 KB Output is correct
6 Correct 48 ms 13564 KB Output is correct
7 Correct 48 ms 13448 KB Output is correct
8 Correct 59 ms 13996 KB Output is correct
9 Correct 57 ms 13976 KB Output is correct
10 Correct 55 ms 13736 KB Output is correct
11 Correct 56 ms 13868 KB Output is correct
12 Correct 53 ms 13820 KB Output is correct
13 Correct 53 ms 13812 KB Output is correct
14 Correct 57 ms 14236 KB Output is correct
15 Correct 60 ms 14072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 13308 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 44 ms 13164 KB Output is correct
4 Correct 65 ms 14588 KB Output is correct
5 Correct 64 ms 14808 KB Output is correct
6 Correct 48 ms 13564 KB Output is correct
7 Correct 48 ms 13448 KB Output is correct
8 Correct 59 ms 13996 KB Output is correct
9 Correct 57 ms 13976 KB Output is correct
10 Correct 55 ms 13736 KB Output is correct
11 Correct 56 ms 13868 KB Output is correct
12 Correct 53 ms 13820 KB Output is correct
13 Correct 53 ms 13812 KB Output is correct
14 Correct 57 ms 14236 KB Output is correct
15 Correct 60 ms 14072 KB Output is correct
16 Correct 43 ms 11768 KB Output is correct
17 Correct 41 ms 11768 KB Output is correct
18 Correct 44 ms 11768 KB Output is correct
19 Correct 45 ms 11836 KB Output is correct
20 Correct 54 ms 12464 KB Output is correct
21 Correct 47 ms 12152 KB Output is correct
22 Correct 55 ms 14076 KB Output is correct
23 Correct 45 ms 11972 KB Output is correct
24 Correct 47 ms 12152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 2 ms 1536 KB Output is correct
4 Correct 2 ms 1536 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 2 ms 1536 KB Output is correct
7 Correct 2 ms 1536 KB Output is correct
8 Correct 2 ms 1536 KB Output is correct
9 Correct 2 ms 1536 KB Output is correct
10 Correct 2 ms 1536 KB Output is correct
11 Correct 2 ms 1536 KB Output is correct
12 Correct 2 ms 1536 KB Output is correct
13 Correct 2 ms 1536 KB Output is correct
14 Correct 2 ms 1536 KB Output is correct
15 Correct 2 ms 1536 KB Output is correct
16 Correct 2 ms 1536 KB Output is correct
17 Correct 2 ms 1536 KB Output is correct
18 Correct 2 ms 1536 KB Output is correct
19 Correct 2 ms 1536 KB Output is correct
20 Correct 2 ms 1536 KB Output is correct
21 Correct 2 ms 1536 KB Output is correct
22 Correct 2 ms 1536 KB Output is correct
23 Correct 2 ms 1536 KB Output is correct
24 Correct 2 ms 1536 KB Output is correct
25 Correct 2 ms 1792 KB Output is correct
26 Correct 2 ms 1536 KB Output is correct
27 Correct 2 ms 2048 KB Output is correct
28 Correct 2 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 11600 KB Output is correct
2 Correct 54 ms 11908 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 38 ms 11404 KB Output is correct
5 Correct 58 ms 12768 KB Output is correct
6 Correct 60 ms 12784 KB Output is correct
7 Correct 48 ms 11872 KB Output is correct
8 Correct 47 ms 11772 KB Output is correct
9 Correct 59 ms 12784 KB Output is correct
10 Correct 60 ms 12668 KB Output is correct
11 Correct 62 ms 12780 KB Output is correct
12 Correct 58 ms 12660 KB Output is correct
13 Correct 60 ms 12916 KB Output is correct
14 Correct 58 ms 12776 KB Output is correct
15 Correct 61 ms 12668 KB Output is correct
16 Correct 58 ms 12780 KB Output is correct
17 Correct 54 ms 12412 KB Output is correct
18 Correct 54 ms 12284 KB Output is correct
19 Correct 55 ms 12276 KB Output is correct
20 Correct 55 ms 12516 KB Output is correct
21 Correct 58 ms 12524 KB Output is correct
22 Correct 59 ms 12508 KB Output is correct
23 Correct 43 ms 11644 KB Output is correct
24 Correct 46 ms 11736 KB Output is correct
25 Correct 46 ms 11772 KB Output is correct
26 Correct 46 ms 11644 KB Output is correct
27 Correct 52 ms 12044 KB Output is correct
28 Correct 51 ms 12292 KB Output is correct
29 Correct 51 ms 12148 KB Output is correct
30 Correct 52 ms 12164 KB Output is correct
31 Correct 46 ms 11996 KB Output is correct
32 Correct 45 ms 11748 KB Output is correct
33 Correct 45 ms 11772 KB Output is correct
34 Correct 46 ms 11880 KB Output is correct
35 Correct 52 ms 11900 KB Output is correct
36 Correct 52 ms 12036 KB Output is correct
37 Correct 53 ms 12456 KB Output is correct
38 Correct 54 ms 12020 KB Output is correct
39 Correct 52 ms 12020 KB Output is correct
40 Correct 50 ms 12036 KB Output is correct
41 Correct 54 ms 12324 KB Output is correct
42 Correct 57 ms 12540 KB Output is correct
43 Correct 55 ms 12296 KB Output is correct
44 Correct 56 ms 12284 KB Output is correct
45 Correct 55 ms 12328 KB Output is correct
46 Correct 53 ms 12332 KB Output is correct
47 Correct 49 ms 11912 KB Output is correct
48 Correct 48 ms 11900 KB Output is correct
49 Correct 49 ms 11904 KB Output is correct
50 Correct 50 ms 11900 KB Output is correct
51 Correct 45 ms 11820 KB Output is correct
52 Correct 46 ms 11820 KB Output is correct
53 Correct 48 ms 11900 KB Output is correct
54 Correct 48 ms 11816 KB Output is correct
55 Correct 45 ms 11820 KB Output is correct
56 Correct 47 ms 11824 KB Output is correct
57 Correct 46 ms 11844 KB Output is correct
58 Correct 46 ms 11764 KB Output is correct
59 Correct 45 ms 11856 KB Output is correct
60 Correct 46 ms 11860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 11516 KB Output is correct
2 Correct 48 ms 11776 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 39 ms 11496 KB Output is correct
5 Correct 60 ms 12896 KB Output is correct
6 Correct 58 ms 12764 KB Output is correct
7 Correct 45 ms 11884 KB Output is correct
8 Correct 47 ms 11884 KB Output is correct
9 Correct 56 ms 12776 KB Output is correct
10 Correct 57 ms 12788 KB Output is correct
11 Correct 56 ms 12668 KB Output is correct
12 Correct 57 ms 12908 KB Output is correct
13 Correct 62 ms 12772 KB Output is correct
14 Correct 59 ms 12776 KB Output is correct
15 Correct 62 ms 12776 KB Output is correct
16 Correct 61 ms 12780 KB Output is correct
17 Correct 54 ms 12516 KB Output is correct
18 Correct 54 ms 12396 KB Output is correct
19 Correct 54 ms 12520 KB Output is correct
20 Correct 58 ms 12524 KB Output is correct
21 Correct 55 ms 12284 KB Output is correct
22 Correct 54 ms 12512 KB Output is correct
23 Correct 44 ms 11760 KB Output is correct
24 Correct 45 ms 11612 KB Output is correct
25 Correct 47 ms 11644 KB Output is correct
26 Correct 47 ms 11904 KB Output is correct
27 Correct 52 ms 12052 KB Output is correct
28 Correct 56 ms 12044 KB Output is correct
29 Correct 54 ms 12020 KB Output is correct
30 Correct 51 ms 12172 KB Output is correct
31 Correct 45 ms 11644 KB Output is correct
32 Correct 44 ms 11680 KB Output is correct
33 Correct 46 ms 11892 KB Output is correct
34 Correct 46 ms 11892 KB Output is correct
35 Correct 56 ms 11984 KB Output is correct
36 Correct 51 ms 12088 KB Output is correct
37 Correct 52 ms 12032 KB Output is correct
38 Correct 51 ms 12084 KB Output is correct
39 Correct 52 ms 11884 KB Output is correct
40 Correct 52 ms 12044 KB Output is correct
41 Correct 54 ms 12156 KB Output is correct
42 Correct 54 ms 12216 KB Output is correct
43 Correct 57 ms 12324 KB Output is correct
44 Correct 58 ms 12280 KB Output is correct
45 Correct 55 ms 12276 KB Output is correct
46 Correct 55 ms 12424 KB Output is correct
47 Correct 50 ms 11908 KB Output is correct
48 Correct 49 ms 11772 KB Output is correct
49 Correct 48 ms 12032 KB Output is correct
50 Correct 50 ms 12028 KB Output is correct
51 Correct 46 ms 11768 KB Output is correct
52 Correct 45 ms 11772 KB Output is correct
53 Correct 45 ms 11804 KB Output is correct
54 Correct 45 ms 11644 KB Output is correct
55 Correct 45 ms 11984 KB Output is correct
56 Correct 47 ms 11816 KB Output is correct
57 Correct 48 ms 11976 KB Output is correct
58 Correct 44 ms 11644 KB Output is correct
59 Correct 45 ms 11996 KB Output is correct
60 Correct 49 ms 11644 KB Output is correct