답안 #719161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
719161 2023-04-05T14:04:08 Z lam 길고양이 (JOI20_stray) C++14
100 / 100
53 ms 16600 KB
#include "Anthony.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
#define ff first
#define ss second
const int maxn = 2e4 + 10;
const string S = "101001";
int n,m;
bool start; int it;
vector <ii> adj[maxn];
vector <int> type;

void dfs(int x, int p, int val)
{
    int cnt = 0;
    for (ii i:adj[x])
        if (i.ff!=p) cnt++;
    if (cnt>1)
    {
        for (ii i:adj[x])
            if (i.ff!=p)
        {
            start = true;
            type[i.ss] = 1-val;
            dfs(i.ff,x,1-val);
        }
    }
    else if (cnt==1)
    {
        if (start)
        {
            start = false;
            if (val==-1||val==1) it = 0;
            else it = 2;
        }
        for (ii i:adj[x])
            if (i.ff!=p)
        {
            type[i.ss] = (S[it]-'0');
            it=(it+1)%6;
            dfs(i.ff,x,type[i.ss]);
        }
    }
}

std::vector<int> Mark(int N, int M, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
    n=N; m=M;
    type.assign(m,0);
    for (int i=0; i<n; i++) adj[i].clear();
    for (int i=0; i<m; i++)
    {
        adj[U[i]].push_back({V[i],i});
        adj[V[i]].push_back({U[i],i});
    }
    if (A>2)
    {
        queue<int> q;
        vector <int> d(n,-1);
        d[0] = 0; q.push(0);
        while (!q.empty())
        {
            int u=q.front(); q.pop();
            for (ii v:adj[u])
                if (d[v.ff]==-1)
            {
                d[v.ff] = d[u]+1;
                q.push(v.ff);
            }
        }
//        for (int i=0; i<n; i++) cerr<<i<<" : "<<d[i]<<endl;
        for (int i=0; i<m; i++)
        {
            int u=U[i]; int v=V[i];
            if (d[u]>d[v]) swap(u,v);
            type[i] = (d[v]%3);
            if (d[u]==d[v]) type[i] = (type[i]+1)%3;
        }
        return type;
    }
    start = true;
    dfs(0,-1,1);
//    for (int i=0; i<m; i++) cerr<<type[i]<<' '; cerr<<endl;
    return type;
}
#include "Catherine.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

bool sub1;
bool _starts, _lost;
int val;
string s;

void Init(int A, int B) {
    if (A>2) sub1=1;
    else
    {
        s="";
        sub1=0;
        _starts = 1;
        _lost = 1;
    }
}

int Move(std::vector<int> y) {
//    cerr<<"? "<<_starts<<' '<<_lost<<' '<<val<<endl;
    if (sub1)
    {
        if ((y[0]>0&&y[1]>0)) return 0;
        if ((y[2]>0&&y[1]>0)) return 1;
        if ((y[0]>0&&y[2]>0)) return 2;
        if (y[0]) return 0;
        if (y[1]) return 1;
        if (y[2]) return 2;
        assert(false);
        return -1;
    }
    else
    {
        if (!_starts&&!_lost)
        {
            if (y[0]+y[1]==1)
            {
                if (y[0]) return val=0;
                else return val=1;
            }
            else if (y[0]+y[1]>1) return val=1-val;
            else return -1;
        }
        if (_starts)
        {
            _starts = false;
            if (y[0]+y[1]==2)
            {
                if (y[0]==2)
                {
                    s+="00";
                    return val=0;
                }
                else if (y[1]==2)
                {
                    s+="11";
                    return val=1;
                }
                else
                {
                    s+="01";
                    return val=1;
                }
            }
            else
            {
                _lost = false;
                if (y[0]==1) return val=0;
                else if (y[1]==1) return val=1;
                else
                {
                    assert(false);
                    return -1;
                }
            }
        }
        if (_lost)
        {
            if (y[0]+y[1]>1)
            {
                if (y[0]==0||y[1]==0)
                {
//                    cerr<<y[0]<<" & "<<y[1]<<endl;
                    _lost = false;
//                    cerr<<val<<" : "<<_starts<<' '<<_lost<<endl;
                    return -1;
                }
                _lost = false;
                return val = 1-val;
            }
            else if (y[0]+y[1]==0)
            {
                _lost = false;
                return -1;
            }
            else
            {
                if (y[0]) s+='0';
                else s+='1';
                if (s.length()==5)
                {
                    if (s=="10100"||s=="01001"||s=="10011"||s=="00110"||s=="01101"||s=="11010")
                    {
                        s="";
                        _lost = false;
                        return -1;
                    }
                    else
                    {
                        s="";
                        _lost = false;
                        if (y[0]) return val=0;
                        else return val=1;
                    }
                }
                else if (y[0]) return val=0;
                else return val=1;
            }
        }
    }
}

Compilation message

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:125:1: warning: control reaches end of non-void function [-Wreturn-type]
  125 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 15456 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 31 ms 14920 KB Output is correct
4 Correct 52 ms 16536 KB Output is correct
5 Correct 46 ms 16600 KB Output is correct
6 Correct 35 ms 15340 KB Output is correct
7 Correct 41 ms 15428 KB Output is correct
8 Correct 48 ms 15952 KB Output is correct
9 Correct 44 ms 15976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 15456 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 31 ms 14920 KB Output is correct
4 Correct 52 ms 16536 KB Output is correct
5 Correct 46 ms 16600 KB Output is correct
6 Correct 35 ms 15340 KB Output is correct
7 Correct 41 ms 15428 KB Output is correct
8 Correct 48 ms 15952 KB Output is correct
9 Correct 44 ms 15976 KB Output is correct
10 Correct 40 ms 13276 KB Output is correct
11 Correct 34 ms 13864 KB Output is correct
12 Correct 32 ms 13788 KB Output is correct
13 Correct 32 ms 13856 KB Output is correct
14 Correct 33 ms 13980 KB Output is correct
15 Correct 41 ms 14468 KB Output is correct
16 Correct 53 ms 16348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 13160 KB Output is correct
2 Correct 1 ms 1028 KB Output is correct
3 Correct 27 ms 12708 KB Output is correct
4 Correct 45 ms 14376 KB Output is correct
5 Correct 44 ms 14328 KB Output is correct
6 Correct 37 ms 13124 KB Output is correct
7 Correct 37 ms 13068 KB Output is correct
8 Correct 45 ms 13656 KB Output is correct
9 Correct 40 ms 13716 KB Output is correct
10 Correct 40 ms 13512 KB Output is correct
11 Correct 46 ms 13528 KB Output is correct
12 Correct 46 ms 13372 KB Output is correct
13 Correct 51 ms 13448 KB Output is correct
14 Correct 41 ms 13800 KB Output is correct
15 Correct 39 ms 13704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 13160 KB Output is correct
2 Correct 1 ms 1028 KB Output is correct
3 Correct 27 ms 12708 KB Output is correct
4 Correct 45 ms 14376 KB Output is correct
5 Correct 44 ms 14328 KB Output is correct
6 Correct 37 ms 13124 KB Output is correct
7 Correct 37 ms 13068 KB Output is correct
8 Correct 45 ms 13656 KB Output is correct
9 Correct 40 ms 13716 KB Output is correct
10 Correct 40 ms 13512 KB Output is correct
11 Correct 46 ms 13528 KB Output is correct
12 Correct 46 ms 13372 KB Output is correct
13 Correct 51 ms 13448 KB Output is correct
14 Correct 41 ms 13800 KB Output is correct
15 Correct 39 ms 13704 KB Output is correct
16 Correct 32 ms 11624 KB Output is correct
17 Correct 38 ms 11892 KB Output is correct
18 Correct 41 ms 11952 KB Output is correct
19 Correct 30 ms 11944 KB Output is correct
20 Correct 37 ms 12524 KB Output is correct
21 Correct 32 ms 12324 KB Output is correct
22 Correct 39 ms 14384 KB Output is correct
23 Correct 31 ms 12092 KB Output is correct
24 Correct 31 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1284 KB Output is correct
2 Correct 1 ms 1020 KB Output is correct
3 Correct 2 ms 1284 KB Output is correct
4 Correct 2 ms 1284 KB Output is correct
5 Correct 2 ms 1292 KB Output is correct
6 Correct 3 ms 1296 KB Output is correct
7 Correct 2 ms 1296 KB Output is correct
8 Correct 2 ms 1284 KB Output is correct
9 Correct 2 ms 1284 KB Output is correct
10 Correct 2 ms 1292 KB Output is correct
11 Correct 2 ms 1292 KB Output is correct
12 Correct 2 ms 1284 KB Output is correct
13 Correct 2 ms 1292 KB Output is correct
14 Correct 2 ms 1204 KB Output is correct
15 Correct 2 ms 1292 KB Output is correct
16 Correct 2 ms 1284 KB Output is correct
17 Correct 2 ms 1292 KB Output is correct
18 Correct 2 ms 1288 KB Output is correct
19 Correct 2 ms 1284 KB Output is correct
20 Correct 2 ms 1284 KB Output is correct
21 Correct 2 ms 1288 KB Output is correct
22 Correct 2 ms 1292 KB Output is correct
23 Correct 2 ms 1284 KB Output is correct
24 Correct 2 ms 1300 KB Output is correct
25 Correct 2 ms 1288 KB Output is correct
26 Correct 2 ms 1284 KB Output is correct
27 Correct 2 ms 1284 KB Output is correct
28 Correct 2 ms 1292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11100 KB Output is correct
2 Correct 39 ms 12196 KB Output is correct
3 Correct 2 ms 1028 KB Output is correct
4 Correct 27 ms 11096 KB Output is correct
5 Correct 47 ms 13568 KB Output is correct
6 Correct 47 ms 13524 KB Output is correct
7 Correct 34 ms 12584 KB Output is correct
8 Correct 34 ms 12680 KB Output is correct
9 Correct 41 ms 13548 KB Output is correct
10 Correct 41 ms 13544 KB Output is correct
11 Correct 38 ms 13552 KB Output is correct
12 Correct 38 ms 13464 KB Output is correct
13 Correct 41 ms 13524 KB Output is correct
14 Correct 39 ms 13484 KB Output is correct
15 Correct 40 ms 13488 KB Output is correct
16 Correct 47 ms 13548 KB Output is correct
17 Correct 38 ms 13204 KB Output is correct
18 Correct 36 ms 13280 KB Output is correct
19 Correct 40 ms 13236 KB Output is correct
20 Correct 37 ms 13156 KB Output is correct
21 Correct 44 ms 13228 KB Output is correct
22 Correct 47 ms 13232 KB Output is correct
23 Correct 31 ms 11104 KB Output is correct
24 Correct 31 ms 11116 KB Output is correct
25 Correct 32 ms 11564 KB Output is correct
26 Correct 44 ms 11588 KB Output is correct
27 Correct 39 ms 12308 KB Output is correct
28 Correct 37 ms 12308 KB Output is correct
29 Correct 40 ms 12304 KB Output is correct
30 Correct 35 ms 12304 KB Output is correct
31 Correct 48 ms 11020 KB Output is correct
32 Correct 35 ms 11092 KB Output is correct
33 Correct 32 ms 11444 KB Output is correct
34 Correct 31 ms 11588 KB Output is correct
35 Correct 36 ms 12264 KB Output is correct
36 Correct 39 ms 12168 KB Output is correct
37 Correct 39 ms 12076 KB Output is correct
38 Correct 39 ms 12216 KB Output is correct
39 Correct 36 ms 12264 KB Output is correct
40 Correct 42 ms 12100 KB Output is correct
41 Correct 41 ms 12700 KB Output is correct
42 Correct 39 ms 12756 KB Output is correct
43 Correct 43 ms 12628 KB Output is correct
44 Correct 41 ms 12660 KB Output is correct
45 Correct 38 ms 12784 KB Output is correct
46 Correct 40 ms 12672 KB Output is correct
47 Correct 36 ms 11928 KB Output is correct
48 Correct 41 ms 12004 KB Output is correct
49 Correct 36 ms 11956 KB Output is correct
50 Correct 34 ms 12140 KB Output is correct
51 Correct 33 ms 11284 KB Output is correct
52 Correct 40 ms 11420 KB Output is correct
53 Correct 40 ms 11344 KB Output is correct
54 Correct 34 ms 11336 KB Output is correct
55 Correct 34 ms 11348 KB Output is correct
56 Correct 35 ms 11324 KB Output is correct
57 Correct 33 ms 11392 KB Output is correct
58 Correct 36 ms 11280 KB Output is correct
59 Correct 34 ms 11292 KB Output is correct
60 Correct 41 ms 11328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 11120 KB Output is correct
2 Correct 38 ms 12060 KB Output is correct
3 Correct 1 ms 1032 KB Output is correct
4 Correct 28 ms 11116 KB Output is correct
5 Correct 48 ms 13528 KB Output is correct
6 Correct 47 ms 13412 KB Output is correct
7 Correct 36 ms 12572 KB Output is correct
8 Correct 46 ms 12588 KB Output is correct
9 Correct 45 ms 13568 KB Output is correct
10 Correct 41 ms 13608 KB Output is correct
11 Correct 40 ms 13612 KB Output is correct
12 Correct 39 ms 13508 KB Output is correct
13 Correct 41 ms 13516 KB Output is correct
14 Correct 39 ms 13492 KB Output is correct
15 Correct 47 ms 13420 KB Output is correct
16 Correct 51 ms 13564 KB Output is correct
17 Correct 39 ms 13276 KB Output is correct
18 Correct 37 ms 13152 KB Output is correct
19 Correct 41 ms 13232 KB Output is correct
20 Correct 40 ms 13216 KB Output is correct
21 Correct 40 ms 13144 KB Output is correct
22 Correct 38 ms 13220 KB Output is correct
23 Correct 31 ms 11104 KB Output is correct
24 Correct 32 ms 11108 KB Output is correct
25 Correct 33 ms 11568 KB Output is correct
26 Correct 33 ms 11544 KB Output is correct
27 Correct 39 ms 12308 KB Output is correct
28 Correct 36 ms 12384 KB Output is correct
29 Correct 35 ms 12360 KB Output is correct
30 Correct 39 ms 12400 KB Output is correct
31 Correct 39 ms 11136 KB Output is correct
32 Correct 33 ms 11152 KB Output is correct
33 Correct 30 ms 11624 KB Output is correct
34 Correct 32 ms 11552 KB Output is correct
35 Correct 36 ms 12100 KB Output is correct
36 Correct 39 ms 12060 KB Output is correct
37 Correct 36 ms 12128 KB Output is correct
38 Correct 36 ms 12136 KB Output is correct
39 Correct 35 ms 12136 KB Output is correct
40 Correct 37 ms 12084 KB Output is correct
41 Correct 46 ms 12796 KB Output is correct
42 Correct 37 ms 12864 KB Output is correct
43 Correct 36 ms 12768 KB Output is correct
44 Correct 37 ms 12756 KB Output is correct
45 Correct 40 ms 12692 KB Output is correct
46 Correct 41 ms 12876 KB Output is correct
47 Correct 42 ms 12104 KB Output is correct
48 Correct 36 ms 12096 KB Output is correct
49 Correct 41 ms 11988 KB Output is correct
50 Correct 44 ms 12136 KB Output is correct
51 Correct 32 ms 11348 KB Output is correct
52 Correct 42 ms 11292 KB Output is correct
53 Correct 33 ms 11352 KB Output is correct
54 Correct 33 ms 11452 KB Output is correct
55 Correct 35 ms 11340 KB Output is correct
56 Correct 37 ms 11320 KB Output is correct
57 Correct 35 ms 11188 KB Output is correct
58 Correct 40 ms 11260 KB Output is correct
59 Correct 30 ms 11364 KB Output is correct
60 Correct 31 ms 11356 KB Output is correct