답안 #939609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939609 2024-03-06T15:06:06 Z pcc 길고양이 (JOI20_stray) C++14
100 / 100
40 ms 16900 KB
#include "Anthony.h"
#include <vector>
#include <bits/stdc++.h>


namespace ANTHONY{

#define pii pair<int,int>
#define fs first
#define sc second
	using namespace std;
	const int mxn = 2e4+10;
	int N,M;
	vector<pii> paths[mxn];
	vector<pii> edges;

	namespace S1{
		queue<int> q;
		int dist[mxn];
		void BFS(){
			memset(dist,-1,sizeof(dist));
			dist[0] = 0;
			q.push(0);
			while(!q.empty()){
				auto now = q.front();
				q.pop();
				for(auto nxt:paths[now]){
					if(dist[nxt.fs] == -1)dist[nxt.fs] = dist[now]+1,q.push(nxt.fs);
				}
			}
			return;
		}
		vector<int> GO(){
			//cout<<"CASE 1"<<endl;
			vector<int> ans(M,0);
			BFS();
			for(int i = 0;i<M;i++){
				auto [a,b] = edges[i];
				if(dist[a]>dist[b])swap(a,b);
				if(dist[a]==dist[b])ans[i] = (dist[a]+1)%3;
				else ans[i] = dist[b]%3;
				//cout<<a<<' '<<b<<" "<<ans[i]<<endl;
			}
			//for(int i = 0;i<N;i++)cout<<dist[i]<<' ';cout<<endl;
			//cout<<ans.size()<<endl;
			//for(auto &i:ans)cout<<i;cout<<endl;
			return ans;
		}
	}

	namespace S2{
		string bin = "100110";//11:0,12:1
		vector<int> ans;
		void dfs(int now,int fa,int pt){
			for(auto nxt:paths[now]){
				if(nxt.fs == fa)continue;
				if(paths[nxt.fs].size() != 2){
					if(pt>10){
						ans[nxt.sc] = (pt==11?0:1);
						dfs(nxt.fs,now,(pt==11?12:11));
					}
					else{
						if(bin[pt]=='0'){
							ans[nxt.sc] = 0;
							dfs(nxt.fs,now,12);
						}
						else{
							ans[nxt.sc] = 1;
							dfs(nxt.fs,now,11);
						}
					}
				}
				else{
					if(pt==11){
						ans[nxt.sc] = 0;
						dfs(nxt.fs,now,0);
					}
					else if(pt == 12){
						ans[nxt.sc] = 1;
						dfs(nxt.fs,now,1);
					}
					else{
						ans[nxt.sc] = bin[pt]-'0';
						dfs(nxt.fs,now,(pt+1)%bin.size());
					}
				}
			}
			return;
		}
		vector<int> GO(){
			ans.resize(M);
			dfs(0,0,11);
			for(int i = 0;i<M;i++){
				//cout<<edges[i].fs<<' '<<edges[i].sc<<" "<<ans[i]<<endl;
			}
			return ans;
		}
	}

	vector<int> SOLVE(int n,int m,int a,int b,vector<int> va,vector<int> vb){
		N = n,M = m;
		for(int i = 0;i<m;i++){
			edges.push_back({va[i],vb[i]});
			paths[va[i]].push_back({vb[i],i});
			paths[vb[i]].push_back({va[i],i});
		}
		if(a>=3)return S1::GO();
		else return S2::GO();
	}
}  // namespace

std::vector<int> Mark(int N, int M, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
  return ANTHONY::SOLVE(N,M,A,B,U,V);
}
#include "Catherine.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second

namespace NEKO{

int task;
vector<int> route;
int turn;

}  // namespace

void Init(int A, int B) {
	NEKO::task = (A<=2);
	NEKO::turn = 3;
	return;
}

namespace S1{
	int GO(vector<int> v){
		int sum = 0;
		for(auto &i:v)sum += (i?1:0);
		if(sum == 1)return max_element(v.begin(),v.end())-v.begin();
		int s = 0;
		for(int i = 0;i<3;i++){
			if(v[i])s ^= i;
		}
		switch(s){
			case 1:
				return 0;
			case 2:
				return 2;
			case 3:
				return 1;
		}
		assert(false);
		return -1;
	}
}

namespace S2{
	int pre = -1;
	int nt = -1;
	int C0(vector<int> v){
		//cout<<"C0"<<endl;
		int s = 0;
		for(auto &i:v)s += (i!=0);
		if(s == 1){
			return (pre = max_element(v.begin(),v.end())-v.begin());
		}
		else if(s == 0)return -1;
		else return (pre ^= 1);
	}
	int C1(vector<int> v){
		//cout<<"C1"<<endl;
		nt = 0;
		for(int i = 0;i<2;i++){
			if(v[i] == 1)return (pre = i);
		}
		assert(false);
	}
	int C2(vector<int> v){
		//cout<<"C2"<<endl;
		int s = (v[0]?0:1);
		NEKO::turn--;
		if(pre == -1){
			NEKO::route.push_back((v[0]?0:1));
			if(v[1])s = 1;
			else s = 0;
			NEKO::route.push_back(s);
			return (pre = s);
		}
		else if(NEKO::turn>=0){
			NEKO::route.push_back(s);
			return (pre = s);
		}
		else if(NEKO::turn == -1){
			NEKO::route.push_back(s);
			return -1;
		}
		else if(NEKO::turn >= -3){
			return (pre = s);
		}
		string ss;
		for(auto &i:NEKO::route){
			ss += '0'+i;
		}
		//cout<<ss<<endl;
		string t = "100110100110100110";
		assert(ss.size() == 5);
		bool flag = false;
		for(int i = 0;i+ss.size()<=t.size();i++){
			if(t.substr(i,ss.size()) == ss)flag = true;
		}
		nt = 0;
		if(flag)return s;
		else return -1;
	}
	int GO(vector<int> v){
		int re = -2;
		if(!nt)re = C0(v);
		int s = 0;
		for(auto &i:v)s +=i;
		if(re == -2&&s + (pre>=0) != 2){
			if(pre == -1){
				nt = 0;
				pre = re = (v[0]==1?0:1);
			}
			else{
				nt = 0;
				if(v[pre] == 0)re = -1;
				else re = (pre ^= 1);
			}
		}
		if(re == -2)re = C2(v);
		//for(auto &i:v)//cout<<i<<' ';cout<<s<<","<<pre<<":"<<re<<endl;
		return re;
	}
}

int Move(std::vector<int> y) {
	if(NEKO::task)return S2::GO(y);
	else return S1::GO(y);
}

Compilation message

Anthony.cpp: In function 'std::vector<int> ANTHONY::S1::GO()':
Anthony.cpp:38:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |     auto [a,b] = edges[i];
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 16140 KB Output is correct
2 Correct 1 ms 1304 KB Output is correct
3 Correct 25 ms 15384 KB Output is correct
4 Correct 40 ms 16900 KB Output is correct
5 Correct 36 ms 16796 KB Output is correct
6 Correct 28 ms 15756 KB Output is correct
7 Correct 32 ms 15752 KB Output is correct
8 Correct 33 ms 16392 KB Output is correct
9 Correct 36 ms 16384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 16140 KB Output is correct
2 Correct 1 ms 1304 KB Output is correct
3 Correct 25 ms 15384 KB Output is correct
4 Correct 40 ms 16900 KB Output is correct
5 Correct 36 ms 16796 KB Output is correct
6 Correct 28 ms 15756 KB Output is correct
7 Correct 32 ms 15752 KB Output is correct
8 Correct 33 ms 16392 KB Output is correct
9 Correct 36 ms 16384 KB Output is correct
10 Correct 27 ms 13816 KB Output is correct
11 Correct 27 ms 13828 KB Output is correct
12 Correct 28 ms 13956 KB Output is correct
13 Correct 32 ms 13824 KB Output is correct
14 Correct 27 ms 14080 KB Output is correct
15 Correct 31 ms 14340 KB Output is correct
16 Correct 32 ms 16464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 13576 KB Output is correct
2 Correct 1 ms 1292 KB Output is correct
3 Correct 22 ms 13076 KB Output is correct
4 Correct 33 ms 14840 KB Output is correct
5 Correct 33 ms 14616 KB Output is correct
6 Correct 33 ms 13568 KB Output is correct
7 Correct 35 ms 13560 KB Output is correct
8 Correct 32 ms 14084 KB Output is correct
9 Correct 31 ms 14080 KB Output is correct
10 Correct 30 ms 13824 KB Output is correct
11 Correct 30 ms 13792 KB Output is correct
12 Correct 34 ms 13920 KB Output is correct
13 Correct 38 ms 13908 KB Output is correct
14 Correct 32 ms 14068 KB Output is correct
15 Correct 31 ms 14064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 13576 KB Output is correct
2 Correct 1 ms 1292 KB Output is correct
3 Correct 22 ms 13076 KB Output is correct
4 Correct 33 ms 14840 KB Output is correct
5 Correct 33 ms 14616 KB Output is correct
6 Correct 33 ms 13568 KB Output is correct
7 Correct 35 ms 13560 KB Output is correct
8 Correct 32 ms 14084 KB Output is correct
9 Correct 31 ms 14080 KB Output is correct
10 Correct 30 ms 13824 KB Output is correct
11 Correct 30 ms 13792 KB Output is correct
12 Correct 34 ms 13920 KB Output is correct
13 Correct 38 ms 13908 KB Output is correct
14 Correct 32 ms 14068 KB Output is correct
15 Correct 31 ms 14064 KB Output is correct
16 Correct 24 ms 12044 KB Output is correct
17 Correct 24 ms 12040 KB Output is correct
18 Correct 26 ms 11908 KB Output is correct
19 Correct 26 ms 11756 KB Output is correct
20 Correct 33 ms 12396 KB Output is correct
21 Correct 27 ms 12292 KB Output is correct
22 Correct 34 ms 14320 KB Output is correct
23 Correct 26 ms 11956 KB Output is correct
24 Correct 27 ms 11836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1560 KB Output is correct
2 Correct 1 ms 1304 KB Output is correct
3 Correct 1 ms 1568 KB Output is correct
4 Correct 2 ms 2072 KB Output is correct
5 Correct 2 ms 1568 KB Output is correct
6 Correct 2 ms 1568 KB Output is correct
7 Correct 2 ms 1568 KB Output is correct
8 Correct 2 ms 1644 KB Output is correct
9 Correct 2 ms 1568 KB Output is correct
10 Correct 2 ms 1564 KB Output is correct
11 Correct 2 ms 2072 KB Output is correct
12 Correct 2 ms 1564 KB Output is correct
13 Correct 2 ms 1560 KB Output is correct
14 Correct 2 ms 1560 KB Output is correct
15 Correct 2 ms 1568 KB Output is correct
16 Correct 1 ms 1568 KB Output is correct
17 Correct 2 ms 1568 KB Output is correct
18 Correct 2 ms 1560 KB Output is correct
19 Correct 2 ms 1820 KB Output is correct
20 Correct 2 ms 1568 KB Output is correct
21 Correct 1 ms 1560 KB Output is correct
22 Correct 2 ms 1568 KB Output is correct
23 Correct 2 ms 1564 KB Output is correct
24 Correct 2 ms 1564 KB Output is correct
25 Correct 2 ms 1556 KB Output is correct
26 Correct 1 ms 1564 KB Output is correct
27 Correct 2 ms 1564 KB Output is correct
28 Correct 2 ms 1568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11672 KB Output is correct
2 Correct 32 ms 13220 KB Output is correct
3 Correct 1 ms 1308 KB Output is correct
4 Correct 22 ms 11652 KB Output is correct
5 Correct 33 ms 14844 KB Output is correct
6 Correct 32 ms 14856 KB Output is correct
7 Correct 28 ms 13740 KB Output is correct
8 Correct 26 ms 13636 KB Output is correct
9 Correct 33 ms 14668 KB Output is correct
10 Correct 31 ms 14848 KB Output is correct
11 Correct 33 ms 14852 KB Output is correct
12 Correct 32 ms 14828 KB Output is correct
13 Correct 32 ms 14660 KB Output is correct
14 Correct 32 ms 14768 KB Output is correct
15 Correct 32 ms 14724 KB Output is correct
16 Correct 40 ms 14860 KB Output is correct
17 Correct 28 ms 14600 KB Output is correct
18 Correct 30 ms 14584 KB Output is correct
19 Correct 28 ms 14332 KB Output is correct
20 Correct 32 ms 14408 KB Output is correct
21 Correct 30 ms 14340 KB Output is correct
22 Correct 37 ms 14444 KB Output is correct
23 Correct 25 ms 11784 KB Output is correct
24 Correct 24 ms 11776 KB Output is correct
25 Correct 28 ms 12284 KB Output is correct
26 Correct 26 ms 12296 KB Output is correct
27 Correct 27 ms 13188 KB Output is correct
28 Correct 27 ms 13188 KB Output is correct
29 Correct 38 ms 13268 KB Output is correct
30 Correct 28 ms 13144 KB Output is correct
31 Correct 25 ms 11784 KB Output is correct
32 Correct 25 ms 11776 KB Output is correct
33 Correct 25 ms 12032 KB Output is correct
34 Correct 26 ms 12292 KB Output is correct
35 Correct 27 ms 13184 KB Output is correct
36 Correct 27 ms 12980 KB Output is correct
37 Correct 27 ms 13196 KB Output is correct
38 Correct 27 ms 13084 KB Output is correct
39 Correct 27 ms 13136 KB Output is correct
40 Correct 35 ms 13084 KB Output is correct
41 Correct 32 ms 13832 KB Output is correct
42 Correct 28 ms 13752 KB Output is correct
43 Correct 40 ms 13792 KB Output is correct
44 Correct 30 ms 13824 KB Output is correct
45 Correct 28 ms 14312 KB Output is correct
46 Correct 32 ms 14000 KB Output is correct
47 Correct 27 ms 12744 KB Output is correct
48 Correct 27 ms 12936 KB Output is correct
49 Correct 27 ms 12680 KB Output is correct
50 Correct 27 ms 12928 KB Output is correct
51 Correct 25 ms 11768 KB Output is correct
52 Correct 25 ms 11776 KB Output is correct
53 Correct 26 ms 11792 KB Output is correct
54 Correct 26 ms 11784 KB Output is correct
55 Correct 25 ms 11780 KB Output is correct
56 Correct 24 ms 11772 KB Output is correct
57 Correct 26 ms 11780 KB Output is correct
58 Correct 26 ms 11772 KB Output is correct
59 Correct 26 ms 11780 KB Output is correct
60 Correct 25 ms 11768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 11784 KB Output is correct
2 Correct 27 ms 12804 KB Output is correct
3 Correct 1 ms 1308 KB Output is correct
4 Correct 22 ms 11528 KB Output is correct
5 Correct 33 ms 14856 KB Output is correct
6 Correct 32 ms 14656 KB Output is correct
7 Correct 26 ms 13836 KB Output is correct
8 Correct 27 ms 13984 KB Output is correct
9 Correct 33 ms 14616 KB Output is correct
10 Correct 33 ms 14596 KB Output is correct
11 Correct 31 ms 14848 KB Output is correct
12 Correct 31 ms 14764 KB Output is correct
13 Correct 32 ms 14692 KB Output is correct
14 Correct 32 ms 14568 KB Output is correct
15 Correct 32 ms 14500 KB Output is correct
16 Correct 31 ms 14664 KB Output is correct
17 Correct 30 ms 14508 KB Output is correct
18 Correct 30 ms 14308 KB Output is correct
19 Correct 31 ms 14564 KB Output is correct
20 Correct 31 ms 14524 KB Output is correct
21 Correct 31 ms 14616 KB Output is correct
22 Correct 30 ms 14596 KB Output is correct
23 Correct 25 ms 11780 KB Output is correct
24 Correct 26 ms 11776 KB Output is correct
25 Correct 27 ms 12308 KB Output is correct
26 Correct 27 ms 12296 KB Output is correct
27 Correct 28 ms 13148 KB Output is correct
28 Correct 34 ms 13068 KB Output is correct
29 Correct 28 ms 13056 KB Output is correct
30 Correct 30 ms 12972 KB Output is correct
31 Correct 24 ms 11780 KB Output is correct
32 Correct 24 ms 11780 KB Output is correct
33 Correct 27 ms 12280 KB Output is correct
34 Correct 28 ms 12300 KB Output is correct
35 Correct 28 ms 12992 KB Output is correct
36 Correct 28 ms 13052 KB Output is correct
37 Correct 28 ms 12972 KB Output is correct
38 Correct 28 ms 13056 KB Output is correct
39 Correct 30 ms 13024 KB Output is correct
40 Correct 27 ms 13140 KB Output is correct
41 Correct 35 ms 13864 KB Output is correct
42 Correct 30 ms 13836 KB Output is correct
43 Correct 31 ms 13736 KB Output is correct
44 Correct 30 ms 13880 KB Output is correct
45 Correct 31 ms 13828 KB Output is correct
46 Correct 30 ms 13912 KB Output is correct
47 Correct 28 ms 12908 KB Output is correct
48 Correct 30 ms 12960 KB Output is correct
49 Correct 27 ms 12648 KB Output is correct
50 Correct 33 ms 12908 KB Output is correct
51 Correct 28 ms 11776 KB Output is correct
52 Correct 26 ms 11772 KB Output is correct
53 Correct 34 ms 11744 KB Output is correct
54 Correct 27 ms 11776 KB Output is correct
55 Correct 26 ms 12240 KB Output is correct
56 Correct 27 ms 12140 KB Output is correct
57 Correct 27 ms 12188 KB Output is correct
58 Correct 30 ms 12240 KB Output is correct
59 Correct 30 ms 12252 KB Output is correct
60 Correct 26 ms 12304 KB Output is correct