답안 #963950

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963950 2024-04-16T05:13:20 Z pcc Alternating Current (BOI18_alternating) C++17
13 / 100
30 ms 600 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

const int mxn = 16;
int N,M;
pii arr[mxn];
int ans = -1;
vector<int> paths[mxn];
int col[mxn];

bool inside(pii r,int p){
	if(r.fs<=r.sc){
		if(r.fs<=p&&p<=r.sc)return true;
		else return false;
	}
	else{
		if(p<=r.fs||p>=r.sc)return true;
		else return false;
	}
}

bool banana(int a,int b){
	pii ta = arr[a],tb = arr[b];
	if(inside(ta,tb.fs)||inside(ta,tb.sc)||inside(tb,ta.fs)||inside(tb,ta.sc))return true;
	else return false;
}

void dfs(int now,int c = 1){
	col[now] = c;
	for(auto nxt:paths[now]){
		if(col[nxt]&&col[nxt] != -c){
			cout<<"impossible\n";
			exit(0);
		}
		if(!col[nxt])dfs(nxt,-c);
	}
	return;
}

vector<int> peko[mxn];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M;
	for(int i = 0;i<M;i++){
		cin>>arr[i].fs>>arr[i].sc;
		arr[i].fs--,arr[i].sc--;
		int k = arr[i].fs;
		while(k != arr[i].sc){
			peko[k].push_back(i);
			k = (k+1)%N;
		}
		peko[k].push_back(i);
	}
	for(int i = 0;i<N;i++){
		if(peko[i].size() == 2){
			int a = peko[i][0],b = peko[i][1];
			paths[a].push_back(b);
			paths[b].push_back(a);
		}
		if(peko[i].size() < 2){
			cout<<"impossible\n";
			return 0;
		}
	}
	for(int i = 0;i<M;i++){
		if(!col[i])dfs(i);
	}
	for(int i = 0;i<(1<<M);i++){
		int dp[mxn] = {};
		for(int j = 0;j<M;j++){
			int k;
			for(k = arr[j].fs;k != arr[j].sc;k = (k+1)%N){
				dp[k] |= 1<<(i&(1<<j)?1:0);
			}
			dp[k] |= 1<<(i&(1<<j)?1:0);
		}
		if(*min_element(dp,dp+N) == 3)ans = i;
	}
	if(ans == -1)assert(false);
	else{
		for(int i = 0;i<M;i++){
			if(ans&(1<<i))cout<<1;
			else cout<<0;
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 352 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 18 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 500 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 348 KB Output is correct
37 Correct 5 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 1 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 352 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 18 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 500 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 348 KB Output is correct
37 Correct 5 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 1 ms 504 KB Output is correct
41 Runtime error 1 ms 348 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 352 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 18 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 500 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 348 KB Output is correct
37 Correct 5 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 1 ms 504 KB Output is correct
41 Runtime error 1 ms 348 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 352 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 18 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 500 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 348 KB Output is correct
37 Correct 5 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 1 ms 504 KB Output is correct
41 Runtime error 1 ms 348 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -