제출 #473473

#제출 시각아이디문제언어결과실행 시간메모리
473473Hamed5001Alternating Current (BOI18_alternating)C++14
13 / 100
3030 ms2124 KiB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int N, M;
vector<pair<int, int>> wires;

bool can(int msk) {
	vector<vector<bool>> cov(2, vector<bool>(N, 0));
	for (int i = M-1, j = 0; i >= 0; i--, j++) {
		bool which = msk & (1 << i);
		for (int k = wires[j].first; k != wires[j].second; (k+=1)%=N) {
			cov[which][k] = 1;
		}
		cov[which][wires[j].second] = 1;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 2; j++) {
			if (!cov[j][i]) return false;
		}
	}

	return true;
}

void solve() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		wires.push_back({--a, --b});
	}
	for (int msk = 0; msk < (1 << M); msk++) {
		if (can(msk)) {
			for (int i = M-1; i >= 0; i--) {
				cout << (1 & (msk >> i));
			}
			return;
		}
	}

	cout << "impossible";
}

int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...