#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
string solve_puzzle(string s, vector<int> c) {
int N = s.size();
int k = c.size();
vector<int> avances1(N, 0);
int actuel = 0;
for (int iCase = N-1; iCase >= 0; iCase--) {
if (s[iCase] == '_') actuel = 0;
else actuel++;
avances1[iCase] = actuel;
}
vector<int> avances2(N, 0);
actuel = 0;
for (int iCase = 0; iCase < N; iCase++) {
if (s[iCase] == '_') actuel = 0;
else actuel++;
avances2[iCase] = actuel;
}
vector<int> limites1(N, 0);
int limiteAct = 0;
int idx = 0;
while (idx < N) {
if (limiteAct < k && avances1[idx] >= c[limiteAct]) {
limites1[idx+c[limiteAct]-1] = limiteAct+1;
for (int i = idx; i < idx+c[limiteAct]-1; i++) {
if (i < N)
limites1[i] = limiteAct;
}
idx += c[limiteAct];
limiteAct++;
}
limites1[idx] = limiteAct;
idx++;
}
vector<int> limites2(N, 0);
limiteAct = k;
idx = N-1;
while (idx >= 0) {
if (limiteAct > 0 && avances2[idx] >= c[limiteAct-1]) {
limites2[idx-c[limiteAct-1]+1] = limiteAct-1;
for (int i = idx; i > idx-c[limiteAct-1]+1; i--) {
if (i >= 0)
limites2[i] = limiteAct;
}
idx -= c[limiteAct-1];
limiteAct--;
}
limites2[idx] = limiteAct;
idx--;
}
vector<bool> white(N, false);
white[0] = (limites2[1] == 0);
white[N-1] = (limites1[N-2] == k);
for (int i = 1; i < N-1; i++) {
white[i] = (limites1[i-1] >= limites2[i+1]);
}
vector<bool> black(N, false);
for (int i = 0; i < N; i++) {
black[i] = (limites1[i] >= limites2[i]);
}
string res;
for (int i = 0; i < N; i++) {
if (black[i] && white[i]) res.push_back('?');
else if (black[i]) res.push_back('X');
else res.push_back('_');
}
return res;
}
Compilation message (stderr)
paint.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
paint_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |