Submission #314767

# Submission time Handle Problem Language Result Execution time Memory
314767 2020-10-21T06:53:50 Z georgerapeanu Stray Cat (JOI20_stray) C++14
96 / 100
66 ms 15872 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 = 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>

using namespace std;

int _a,_b;

void Init(int A, int B) {
    _a = A;
    _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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 15872 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 15872 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 13644 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 40 ms 13044 KB Output is correct
4 Correct 66 ms 14996 KB Output is correct
5 Correct 64 ms 14980 KB Output is correct
6 Correct 48 ms 13772 KB Output is correct
7 Correct 49 ms 13800 KB Output is correct
8 Correct 59 ms 14504 KB Output is correct
9 Correct 57 ms 14484 KB Output is correct
10 Correct 62 ms 14228 KB Output is correct
11 Correct 54 ms 14352 KB Output is correct
12 Correct 54 ms 14288 KB Output is correct
13 Correct 55 ms 14228 KB Output is correct
14 Correct 58 ms 14628 KB Output is correct
15 Correct 59 ms 14576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 13644 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 40 ms 13044 KB Output is correct
4 Correct 66 ms 14996 KB Output is correct
5 Correct 64 ms 14980 KB Output is correct
6 Correct 48 ms 13772 KB Output is correct
7 Correct 49 ms 13800 KB Output is correct
8 Correct 59 ms 14504 KB Output is correct
9 Correct 57 ms 14484 KB Output is correct
10 Correct 62 ms 14228 KB Output is correct
11 Correct 54 ms 14352 KB Output is correct
12 Correct 54 ms 14288 KB Output is correct
13 Correct 55 ms 14228 KB Output is correct
14 Correct 58 ms 14628 KB Output is correct
15 Correct 59 ms 14576 KB Output is correct
16 Correct 44 ms 12108 KB Output is correct
17 Correct 43 ms 12396 KB Output is correct
18 Correct 45 ms 12236 KB Output is correct
19 Correct 43 ms 12336 KB Output is correct
20 Correct 54 ms 12980 KB Output is correct
21 Correct 51 ms 12552 KB Output is correct
22 Correct 56 ms 14548 KB Output is correct
23 Correct 47 ms 12460 KB Output is correct
24 Correct 46 ms 12468 KB Output is correct
# Verdict Execution time Memory 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 1536 KB Output is correct
26 Correct 2 ms 1536 KB Output is correct
27 Correct 2 ms 1536 KB Output is correct
28 Correct 2 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 11988 KB Output is correct
2 Correct 51 ms 12156 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 39 ms 11776 KB Output is correct
5 Correct 59 ms 13032 KB Output is correct
6 Correct 59 ms 13160 KB Output is correct
7 Correct 48 ms 12028 KB Output is correct
8 Correct 48 ms 12040 KB Output is correct
9 Correct 58 ms 12924 KB Output is correct
10 Correct 61 ms 13028 KB Output is correct
11 Correct 62 ms 13036 KB Output is correct
12 Correct 63 ms 13024 KB Output is correct
13 Correct 59 ms 13108 KB Output is correct
14 Correct 62 ms 13036 KB Output is correct
15 Correct 60 ms 13028 KB Output is correct
16 Correct 60 ms 13020 KB Output is correct
17 Correct 56 ms 12736 KB Output is correct
18 Correct 57 ms 12772 KB Output is correct
19 Correct 62 ms 12764 KB Output is correct
20 Correct 56 ms 12788 KB Output is correct
21 Correct 57 ms 12760 KB Output is correct
22 Correct 57 ms 12532 KB Output is correct
23 Correct 45 ms 11900 KB Output is correct
24 Correct 44 ms 11900 KB Output is correct
25 Correct 49 ms 12152 KB Output is correct
26 Correct 46 ms 12028 KB Output is correct
27 Correct 51 ms 12296 KB Output is correct
28 Correct 52 ms 12284 KB Output is correct
29 Correct 56 ms 12276 KB Output is correct
30 Correct 52 ms 12412 KB Output is correct
31 Correct 44 ms 12028 KB Output is correct
32 Correct 44 ms 12012 KB Output is correct
33 Correct 46 ms 12020 KB Output is correct
34 Correct 46 ms 12136 KB Output is correct
35 Correct 54 ms 12308 KB Output is correct
36 Correct 51 ms 12156 KB Output is correct
37 Correct 54 ms 12404 KB Output is correct
38 Correct 52 ms 12296 KB Output is correct
39 Correct 51 ms 12292 KB Output is correct
40 Correct 52 ms 12284 KB Output is correct
41 Correct 55 ms 12760 KB Output is correct
42 Correct 55 ms 12572 KB Output is correct
43 Correct 55 ms 12552 KB Output is correct
44 Correct 56 ms 12660 KB Output is correct
45 Correct 55 ms 12540 KB Output is correct
46 Correct 57 ms 12584 KB Output is correct
47 Correct 50 ms 12288 KB Output is correct
48 Correct 50 ms 12284 KB Output is correct
49 Correct 50 ms 12032 KB Output is correct
50 Correct 53 ms 12272 KB Output is correct
51 Correct 48 ms 12076 KB Output is correct
52 Correct 45 ms 12072 KB Output is correct
53 Correct 46 ms 12060 KB Output is correct
54 Correct 45 ms 12076 KB Output is correct
55 Correct 45 ms 12072 KB Output is correct
56 Correct 45 ms 12096 KB Output is correct
57 Correct 45 ms 12240 KB Output is correct
58 Correct 44 ms 11972 KB Output is correct
59 Correct 47 ms 11964 KB Output is correct
60 Correct 45 ms 12132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 11772 KB Output is correct
2 Correct 48 ms 12036 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 39 ms 11568 KB Output is correct
5 Correct 61 ms 13044 KB Output is correct
6 Correct 59 ms 12924 KB Output is correct
7 Correct 45 ms 12140 KB Output is correct
8 Correct 47 ms 12028 KB Output is correct
9 Correct 61 ms 12916 KB Output is correct
10 Correct 62 ms 13028 KB Output is correct
11 Correct 60 ms 13028 KB Output is correct
12 Correct 60 ms 13028 KB Output is correct
13 Correct 58 ms 13028 KB Output is correct
14 Correct 60 ms 12924 KB Output is correct
15 Correct 58 ms 12916 KB Output is correct
16 Correct 59 ms 13016 KB Output is correct
17 Correct 55 ms 12816 KB Output is correct
18 Correct 55 ms 12788 KB Output is correct
19 Correct 56 ms 12792 KB Output is correct
20 Correct 59 ms 12920 KB Output is correct
21 Correct 56 ms 12616 KB Output is correct
22 Correct 56 ms 12784 KB Output is correct
23 Correct 44 ms 11996 KB Output is correct
24 Correct 44 ms 11992 KB Output is correct
25 Correct 48 ms 12020 KB Output is correct
26 Correct 46 ms 11908 KB Output is correct
27 Correct 58 ms 12296 KB Output is correct
28 Correct 51 ms 12416 KB Output is correct
29 Correct 53 ms 12428 KB Output is correct
30 Correct 53 ms 12296 KB Output is correct
31 Correct 44 ms 11984 KB Output is correct
32 Correct 44 ms 11780 KB Output is correct
33 Correct 47 ms 11892 KB Output is correct
34 Correct 46 ms 12028 KB Output is correct
35 Correct 52 ms 12348 KB Output is correct
36 Correct 51 ms 12156 KB Output is correct
37 Correct 52 ms 12292 KB Output is correct
38 Correct 52 ms 12404 KB Output is correct
39 Correct 52 ms 12284 KB Output is correct
40 Correct 51 ms 12288 KB Output is correct
41 Correct 57 ms 12704 KB Output is correct
42 Correct 56 ms 12588 KB Output is correct
43 Correct 59 ms 12404 KB Output is correct
44 Correct 54 ms 12588 KB Output is correct
45 Correct 55 ms 12592 KB Output is correct
46 Correct 54 ms 12592 KB Output is correct
47 Correct 54 ms 12152 KB Output is correct
48 Correct 50 ms 12020 KB Output is correct
49 Correct 49 ms 12032 KB Output is correct
50 Correct 51 ms 12480 KB Output is correct
51 Correct 46 ms 12224 KB Output is correct
52 Correct 45 ms 12064 KB Output is correct
53 Correct 46 ms 12072 KB Output is correct
54 Correct 47 ms 12200 KB Output is correct
55 Correct 46 ms 12336 KB Output is correct
56 Correct 45 ms 12020 KB Output is correct
57 Correct 44 ms 12116 KB Output is correct
58 Correct 46 ms 12028 KB Output is correct
59 Correct 45 ms 12028 KB Output is correct
60 Correct 46 ms 12248 KB Output is correct