답안 #939988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939988 2024-03-07T03:26:06 Z guagua0407 길고양이 (JOI20_stray) C++17
85 / 100
47 ms 29000 KB
#include "Anthony.h"
#include <vector>
#include<bits/stdc++.h>

namespace {

using namespace std;
#define f first
#define s second
int A,B;
const int mxn=2e4+5;
vector<pair<int,int>> adj[mxn];
vector<int> ans;
vector<int> ch={0,0,1,0,1,1};
bool visited[mxn];
int depth[mxn];
int par[mxn];

void dfs(int v,int p=-1,int c=0,int cur=-1){
    for(auto u:adj[v]){
        if(u.f==p) continue;
        if(v!=0 and (int)adj[v].size()==2){
            if(cur==-1){
                if(c==0) cur=2;
                else cur=0;
            }
            ans[u.s]=ch[cur];
            dfs(u.f,v,ans[u.s],(cur+1)%6);
        }
        else{
            ans[u.s]=(c+1)%2;
            dfs(u.f,v,ans[u.s],-1);
        }
    }
}

void bfs(){
    queue<pair<int,int>> q;
    q.push({0,0});
    visited[0]=true;
    while(!q.empty()){
        int v=q.front().f;
        int c=q.front().s;
        q.pop();
        for(auto u:adj[v]){
            if(visited[u.f]){
                if(u.f!=par[v]){
                    if(depth[v]==depth[u.f]){
                        ans[u.s]=(c+1)%3;
                    }
                    else if(depth[v]<depth[u.f]){
                        ans[u.s]=(c+1)%3;
                    }
                }
                continue;
            }
            visited[u.f]=true;
            ans[u.s]=(c+1)%3;
            depth[u.f]=depth[v]+1;
            q.push({u.f,ans[u.s]});
        }
    }
}

}  // namespace

std::vector<int> Mark(int N, int M, int A, int B,std::vector<int> U, std::vector<int> V) {
    ::A = A;
    ::B = B;
    ans.resize(M);
    for(int i=0;i<M;i++){
        adj[U[i]].push_back({V[i],i});
        adj[V[i]].push_back({U[i],i});
    }
    if(M==N-1) dfs(0);
    else bfs();
    //ans=vector<int>(M,0);
    return ans;
}
#include "Catherine.h"
#include <vector>
#include<bits/stdc++.h>
namespace {
using namespace std;
#define all(x) x.begin(),x.end()
int A, B;
int variable_example = 0;
int prv=-1;
map<vector<int>,int> down,up;
vector<int> ch={0,0,1,0,1,1};
bool on=false;
bool dir=false;
vector<int> cur;

}  // namespace

void Init(int A, int B) {
    ::A = A;
    ::B = B;
    for(int i=0;i<6;i++){
        vector<int> tmp;
        for(int j=0;j<5;j++){
            tmp.push_back(ch[(i+j)%6]);
        }
        down[tmp]++;
    }
    reverse(all(ch));
    for(int i=0;i<6;i++){
        vector<int> tmp;
        for(int j=0;j<5;j++){
            tmp.push_back(ch[(i+j)%6]);
        }
        up[tmp]++;
    }
}

int Move(std::vector<int> y) {
    if(B!=0){
        if(prv!=-1) y[prv]++;
        if((y[0]>1 and y[1]==1) or (y[1]>1 and y[0]==1)){
            dir=true;
            if(y[0]>1){
                if(prv==1){
                    prv=1;
                    return -1;
                }
                else{
                    prv=1;
                    return 1;
                }
            }
            else{
                if(prv==0){
                    prv=0;
                    return -1;
                }
                else{
                    prv=0;
                    return 0;
                }
            }
        }
        if(y[0]+y[1]==1){
            dir=true;
            if(y[0]==1){
                if(prv==-1){
                    prv=0;
                    return 0;
                }
                else{
                    prv=0;
                    return -1;
                }
            }
            else{
                if(prv==-1){
                    prv=1;
                    return 1;
                }
                else{
                    prv=1;
                    return -1;
                }
            }
        }
        if(dir==true){
            y[prv]--;
            if(y[0]>0){
                prv=0;
            }
            else{
                prv=1;
            }
            return prv;
        }
        if(on==true){
            cur.push_back(prv);
            if((int)cur.size()==4){
                y[prv]--;
                if(y[0]>0) cur.push_back(0);
                else cur.push_back(1);
                y[prv]++;
                if(up.find(cur)!=up.end()){
                    dir=true;
                    prv=cur.back();
                    return prv;
                }
                else{
                    dir=true;
                    return -1;
                }
            }
            else{
                y[prv]--;
                if(y[0]>0){
                    prv=0;
                    return prv;
                }
                else{
                    prv=1;
                    return prv;
                }
            }
        }
        else{
            on=true;
            vector<int> edge;
            for(int i=0;i<2;i++){
                for(int j=0;j<y[i];j++) edge.push_back(i);
            }
            cur.push_back(edge[0]);
            prv=edge[1];
            return prv;
        }
    }
    else{
        vector<int> pos;
        for(int i=0;i<(int)y.size();i++){
            if(y[i]>0) pos.push_back(i);
        }
        if((int)pos.size()==1) return pos[0];
        else{
            if((pos[0]+1)%3==pos[1]) return pos[0];
            else return pos[1];
        }
    }
}

Compilation message

Catherine.cpp:8:5: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
    8 | int variable_example = 0;
      |     ^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 29000 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 29000 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 24568 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 24568 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1572 KB Output is correct
2 Correct 1 ms 1300 KB Output is correct
3 Correct 1 ms 1556 KB Output is correct
4 Correct 2 ms 1564 KB Output is correct
5 Correct 2 ms 1556 KB Output is correct
6 Correct 2 ms 1572 KB Output is correct
7 Correct 2 ms 1564 KB Output is correct
8 Correct 2 ms 1572 KB Output is correct
9 Correct 2 ms 1564 KB Output is correct
10 Correct 2 ms 1564 KB Output is correct
11 Correct 2 ms 1568 KB Output is correct
12 Correct 2 ms 1564 KB Output is correct
13 Correct 2 ms 1564 KB Output is correct
14 Correct 2 ms 1564 KB Output is correct
15 Correct 2 ms 1572 KB Output is correct
16 Correct 2 ms 1572 KB Output is correct
17 Correct 2 ms 1564 KB Output is correct
18 Correct 2 ms 1620 KB Output is correct
19 Correct 2 ms 1572 KB Output is correct
20 Correct 2 ms 1564 KB Output is correct
21 Correct 2 ms 1832 KB Output is correct
22 Correct 2 ms 1568 KB Output is correct
23 Correct 2 ms 1572 KB Output is correct
24 Correct 2 ms 1564 KB Output is correct
25 Correct 2 ms 1572 KB Output is correct
26 Correct 2 ms 1560 KB Output is correct
27 Correct 2 ms 1564 KB Output is correct
28 Correct 2 ms 1572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 11696 KB Output is correct
2 Correct 30 ms 13128 KB Output is correct
3 Correct 1 ms 1296 KB Output is correct
4 Correct 31 ms 11376 KB Output is correct
5 Correct 32 ms 14428 KB Output is correct
6 Correct 40 ms 14484 KB Output is correct
7 Correct 34 ms 13476 KB Output is correct
8 Correct 31 ms 13480 KB Output is correct
9 Correct 34 ms 14420 KB Output is correct
10 Correct 37 ms 14416 KB Output is correct
11 Correct 35 ms 14352 KB Output is correct
12 Correct 32 ms 14916 KB Output is correct
13 Correct 34 ms 14600 KB Output is correct
14 Correct 40 ms 14492 KB Output is correct
15 Correct 47 ms 14488 KB Output is correct
16 Correct 33 ms 14424 KB Output is correct
17 Correct 34 ms 14144 KB Output is correct
18 Correct 33 ms 14036 KB Output is correct
19 Correct 36 ms 14060 KB Output is correct
20 Correct 37 ms 14328 KB Output is correct
21 Correct 28 ms 14276 KB Output is correct
22 Correct 35 ms 14180 KB Output is correct
23 Correct 32 ms 11916 KB Output is correct
24 Correct 30 ms 11928 KB Output is correct
25 Correct 34 ms 11992 KB Output is correct
26 Correct 28 ms 12332 KB Output is correct
27 Correct 30 ms 13380 KB Output is correct
28 Correct 34 ms 13216 KB Output is correct
29 Correct 45 ms 13332 KB Output is correct
30 Correct 31 ms 13240 KB Output is correct
31 Correct 29 ms 11812 KB Output is correct
32 Correct 28 ms 11824 KB Output is correct
33 Correct 28 ms 12356 KB Output is correct
34 Correct 26 ms 12372 KB Output is correct
35 Correct 28 ms 12824 KB Output is correct
36 Correct 34 ms 12800 KB Output is correct
37 Correct 30 ms 12888 KB Output is correct
38 Correct 28 ms 12864 KB Output is correct
39 Correct 27 ms 12868 KB Output is correct
40 Correct 31 ms 12932 KB Output is correct
41 Correct 31 ms 13448 KB Output is correct
42 Correct 34 ms 13640 KB Output is correct
43 Correct 34 ms 13564 KB Output is correct
44 Correct 30 ms 13724 KB Output is correct
45 Correct 34 ms 13804 KB Output is correct
46 Correct 28 ms 13708 KB Output is correct
47 Correct 27 ms 12892 KB Output is correct
48 Correct 26 ms 12876 KB Output is correct
49 Correct 26 ms 12836 KB Output is correct
50 Correct 38 ms 12724 KB Output is correct
51 Correct 33 ms 12232 KB Output is correct
52 Correct 27 ms 11868 KB Output is correct
53 Correct 28 ms 11836 KB Output is correct
54 Correct 25 ms 11840 KB Output is correct
55 Correct 26 ms 11888 KB Output is correct
56 Correct 26 ms 11900 KB Output is correct
57 Correct 27 ms 12100 KB Output is correct
58 Correct 28 ms 12028 KB Output is correct
59 Correct 25 ms 11856 KB Output is correct
60 Correct 28 ms 11856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 11960 KB Output is correct
2 Correct 27 ms 12884 KB Output is correct
3 Correct 1 ms 1300 KB Output is correct
4 Correct 20 ms 11576 KB Output is correct
5 Correct 34 ms 14408 KB Output is correct
6 Correct 38 ms 14360 KB Output is correct
7 Correct 28 ms 13472 KB Output is correct
8 Correct 28 ms 13388 KB Output is correct
9 Correct 45 ms 14368 KB Output is correct
10 Correct 34 ms 14412 KB Output is correct
11 Correct 31 ms 14552 KB Output is correct
12 Correct 33 ms 14420 KB Output is correct
13 Correct 32 ms 14380 KB Output is correct
14 Correct 36 ms 14332 KB Output is correct
15 Correct 32 ms 14300 KB Output is correct
16 Correct 31 ms 14384 KB Output is correct
17 Correct 30 ms 14152 KB Output is correct
18 Correct 30 ms 14164 KB Output is correct
19 Correct 30 ms 14132 KB Output is correct
20 Correct 30 ms 14160 KB Output is correct
21 Correct 30 ms 14168 KB Output is correct
22 Correct 30 ms 14100 KB Output is correct
23 Correct 25 ms 11848 KB Output is correct
24 Correct 25 ms 11848 KB Output is correct
25 Correct 26 ms 12272 KB Output is correct
26 Correct 31 ms 12632 KB Output is correct
27 Correct 30 ms 13556 KB Output is correct
28 Correct 30 ms 13384 KB Output is correct
29 Correct 28 ms 13376 KB Output is correct
30 Correct 28 ms 13392 KB Output is correct
31 Correct 24 ms 11756 KB Output is correct
32 Correct 26 ms 12108 KB Output is correct
33 Correct 26 ms 12436 KB Output is correct
34 Correct 26 ms 12372 KB Output is correct
35 Correct 28 ms 12880 KB Output is correct
36 Correct 28 ms 12872 KB Output is correct
37 Correct 28 ms 13256 KB Output is correct
38 Correct 26 ms 12888 KB Output is correct
39 Correct 28 ms 12856 KB Output is correct
40 Correct 27 ms 13356 KB Output is correct
41 Correct 30 ms 13628 KB Output is correct
42 Correct 30 ms 13652 KB Output is correct
43 Correct 28 ms 13652 KB Output is correct
44 Correct 30 ms 13568 KB Output is correct
45 Correct 35 ms 13808 KB Output is correct
46 Correct 30 ms 13572 KB Output is correct
47 Correct 26 ms 12784 KB Output is correct
48 Correct 31 ms 12876 KB Output is correct
49 Correct 30 ms 12628 KB Output is correct
50 Correct 30 ms 12708 KB Output is correct
51 Correct 26 ms 11852 KB Output is correct
52 Correct 26 ms 12104 KB Output is correct
53 Correct 27 ms 11776 KB Output is correct
54 Correct 26 ms 11856 KB Output is correct
55 Correct 25 ms 12300 KB Output is correct
56 Correct 25 ms 12168 KB Output is correct
57 Correct 25 ms 12088 KB Output is correct
58 Correct 25 ms 12108 KB Output is correct
59 Correct 27 ms 11848 KB Output is correct
60 Correct 25 ms 11948 KB Output is correct