CSES - NOI 2019 - Results
Submission details
Task:Thieves and Prisons
Sender:Árni
Submission time:2019-03-06 14:13:29 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:19:22: error: 'pow' was not declared in this scope
  for (int i = 0; i < pow(2, c); i++) {
                      ^~~
input/code.cpp:19:22: note: suggested alternative: 'putw'
  for (int i = 0; i < pow(2, c); i++) {
                      ^~~
                      putw
input/code.cpp:41:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int l = 0; l < pris[1].size(); l++) {
                      ~~^~~~~~~~~~~~~~~~
input/code.cpp:48:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int l = 0; l < pris[0].size(); l++) {
                      ~~^~~~~~~~~~~~~~~~

Code

#include <iostream>
#include<vector>
#include <string>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	vector<int> thief(a+1);
	for (int i = 1; i < a+1; i++) {
		thief[i] = i;
	}
	vector<string> move1(c);
	vector<int> move2(c);
	for(int i = 0; i < c; i++) {
		cin >> move1[i] >> move2[i];
	}
	for (int i = 0; i < pow(2, c); i++) {
		for (int i = 1; i < a + 1; i++) {
			thief[i] = i;
		}
		vector<vector<int>> pris(2, vector<int>(10,0));
		int p = 0;
		int q = 0;
		for (int j = 0; j < c; j++) {
			if (move1[j] == "C" && thief[move2[j]] != 0 ) {
				if ((i >> j) & 1) {
					pris[1][p] = move2[j];
					p++;
					thief[move2[j]] = 0;
				}
				else {
					pris[0][q] = move2[j];
					q++;
					thief[move2[j]] = 0;
				}
			}
			else if(move1[j] == "O" && thief[move2[j]] !=0){
				if ((i >> j) && 1 && pris[1][0] != 0) {
					for (int l = 0; l < pris[1].size(); l++) {
						thief[pris[1][l]] = pris[1][l];
						pris[1][l] = 0;
					}
					p = 0;
				}
				else if (pris[0][0] != 0) {
					for (int l = 0; l < pris[0].size(); l++) {
						thief[pris[0][l]] = pris[0][l];
						pris[0][l] = 0;
					}
					q = 0;
				}
				else {
					break;
				}
			}
			else {
				break;
			}
			if (j == c-1) {
				for (int h = 0; h < c; h++) {
					if ((i >> h) && 1) {
						cout << 2 << " ";
					}
					else {
						cout << 1 << " ";						}
				}
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE";
	return 0;
}