Submission #1047145

#TimeUsernameProblemLanguageResultExecution timeMemory
1047145pawnedPaint By Numbers (IOI16_paint)C++17
10 / 100
230 ms420 KiB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

#include "paint.h"

string solve_puzzle(string s, vi c) {
	int N = s.size();
	int K = c.size();
	// try all combinations of _ and X
	// check if each works
	string ans(N, '!');
	for (int i = 0; i < (1 << N); i++) {
		string t;
		for (int j = 0; j < N; j++) {
			if (i & (1 << j))
				t += 'X';
			else
				t += '_';
		}
		bool can = true;
		for (int j = 0; j < N; j++) {
			if (s[j] != '.' && t[j] != s[j])
				can = false;
		}
		if (!can)
			continue;
		// find all component sizes
		vi res;
		int cs = 0;	// current comp size
		for (int j = 0; j < N; j++) {
			if (t[j] == 'X') {
				cs++;
			}
			else {
				if (cs != 0)
					res.pb(cs);
				cs = 0;
			}
		}
		if (cs != 0)
			res.pb(cs);
		if (res.size() != K)
			continue;
		bool works = true;
		for (int j = 0; j < K; j++) {
			if (res[j] != c[j]) {
				works = false;
				break;
			}
		}
		if (works) {
//			cout<<"t: "<<t<<endl;
			for (int j = 0; j < N; j++) {
				if (ans[j] == '!') {
					ans[j] = t[j];
				}
				else if (ans[j] == 'X') {
					if (t[j] == '_')
						ans[j] = '?';
				}
				else if (ans[j] == '_') {
					if (t[j] == 'X')
						ans[j] = '?';
				}
			}
		}
	}
	return ans;
}

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, vi)':
paint.cpp:51:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |   if (res.size() != K)
      |       ~~~~~~~~~~~^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...