CSES - NOI 2019 - Results
Submission details
Task:Thieves and Prisons
Sender:Akseli Jussinmäki
Submission time:2019-03-06 15:56:04 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:91:37: error: 'i' was not declared in this scope
   if (t[m][0]==1 && t[m-1][0]==1) r[i]=2;
                                     ^

Code

#include <bits/stdc++.h>
using namespace std;
int t[100001][5], r[100001];
int n, k, m, a, b=1, c=100000;
void g(){
	b=0;
	c=100000;
	for (int i=1; i<=m && b==0; ++i){
		if (t[i][0]==0 && i<m) {
			a=0;
			for (int j=i+1; j<=m && a==0; ++j){
				if (t[i][1]==t[j][1]) {
					a=1;
					b=1;
					c=j;
				}
				else if (t[j][0]==1 && r[i]==r[j]) a=2;
			}
		}
		if (t[i][0]==1){
			if (i==1) {
				b=1;
				c=i;
			}
			else {
				a=0;
				for (int j=i-1; j>0 && a==0; --j){
					if (t[j][0]==1 && r[i]==r[j]) a=2;
					else if (t[j][0]==0 && r[i]==r[j]) a=1;
				}
				if (a==0 || a==2) {
					b=1;
					c=i;
				}
			}
		}
	}
	if (b==0) {
		for (int i=1; i<=m; ++i) cout << r[i] << " ";
	}
}
void f(int d){
	if (b>0){
		if (d==m+1) {
			g();
			return;
		}
		else{
			if (c<d) return;
			if (c==d) c=100000;
			f(d+1);
			if (c<d) return;
			if (c==d) c=100000;
			r[d]=2;
			f(d+1);
			r[d]=1;
			return;
		}
	}
}
int main(){
	cin >> n >> k >> m;
	char c;
	for (int i=1; i<=m; ++i) r[i]=1;
	for (int i=1; i<=m; ++i){
		cin >> c >> a;
		if (c=='O') t[i][0]=1;
		t[i][1]=a;
	}
	if (m<11){
		f(1);
		if (b==1) cout << "IMPOSSIBLE";
	}
	else {
		b=0;
		if (t[1][0]==1) {
			b=1;
		}
		for (int i=2; i<m; ++i){
			if (t[i][0]==0 && t[i+1][0]==0)
			if (t[i][0]==0 && t[i+1][0]==1){
				if (t[i-1][0]==0) r[i]=2;
			}
			if (t[i][0]==1){
				if (t[i-1][0]==1){
					if (t[i+1][0]==1) b=1;
					else r[i]=2;
				}
			}
		}
		if (t[m][0]==1 && t[m-1][0]==1) r[i]=2;
		if (b==1) cout << "IMPOSSIBLE";
		else {
			for (int i=1; i<=m; ++i) cout << r[i] << " ";
		}
	}
}