Submission #51583

#TimeUsernameProblemLanguageResultExecution timeMemory
51583MatheusLealVPaint By Numbers (IOI16_paint)C++17
100 / 100
1179 ms51900 KiB
#include "paint.h"
#include <bits/stdc++.h>
#define N 200050
using namespace std;
 
int n, k, branco[N], preto[N];
 
int qbranco(int l, int r)
{
	if(!l) return branco[r];
 
	return branco[r] - branco[l - 1];
}
 
int qpreto(int l, int r)
{
	if(!l) return preto[r];
 
	return preto[r] - preto[l - 1];
}
 
char s[N];
 
int W[N], B[N];
 
bool L[N][120], R[N][120];
 
string solve_puzzle(string S, vector<int> c)
{
    n = S.size(), k = c.size();
 
    n ++;
 
    s[n] = '_';
 
    for(int i = 1; i < n; i++) s[i] = S[i - 1];
 
    for(int i = 1; i <= n; i++)
    {
    	preto[i] = preto[i - 1] + (s[i] == 'X');
 
    	branco[i] = branco[i - 1] + (s[i] == '_');
    }
 
    L[0][0] = 1;
 
    for(int q = 0; q <= k; q++)
    {
    	for(int i = 1; i <= n; i++)
    	{
    		if(s[i] == 'X') continue;
 
    		L[i][q] = L[i - 1][q];
 
    		if(q > 0 and i - c[q - 1] - 1 >= 0 and !qbranco(i - c[q - 1], i - 1)) L[i][q] |= L[i - c[q - 1] - 1][q - 1];
    	}
    }
 
    R[n + 1][k] = 1;
 
    for(int q = k; q >= 0; q--)
    {
    	for(int i = n; i >= 1; i--)
    	{
    		if(s[i] != 'X') R[i][q] = R[i + 1][q];
 
    		if(q < k and i + c[q] <= n  and !qbranco(i, i + c[q] - 1) and s[i + c[q]] != 'X') R[i][q] |= R[i + c[q] + 1][q + 1];
    	}
    }
 
    for(int i = 1; i < n; i++)
    	for(int q = 0; q <= k; q++)
    		if(L[i][q] and R[i + 1][q] and s[i] != 'X') W[i] = 1;
 
	for(int q = 1; q <= k; q++)
	{
		for(int i = 1; i <= n; i++)
		{
			if(i + c[q - 1] > n) continue;

    		if(L[i - 1][q - 1] and R[i + c[q - 1] + 1][q] and s[i - 1] != 'X' and s[i + c[q - 1]] != 'X' and !qbranco(i, i + c[q - 1] - 1))
    		{
    			B[i] ++;
 
    			B[i + c[q - 1]] --;
    		}
    	}
    }
 
    string ans;
 
    for(int i = 1; i < n; i++)
    {
    	B[i] += B[i - 1];
 
    	if(W[i] and B[i]) ans.push_back('?');
 
    	else if(W[i]) ans.push_back('_');
 
    	else if(B[i]) ans.push_back('X');
 
    	else ans.push_back('?');
    }
 
    return ans;
}

Compilation message (stderr)

paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:71:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(int i = 1; i < n; i++)
     ^~~
paint.cpp:75:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for(int q = 1; q <= k; q++)
  ^~~
#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...