// intended to solve subtasks 1-4
// but doesn't work because doesn't determine possible overlaps between non leftmost and non rightmost sequences
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
// #define F first
// #define S second
#include "paint.h"
std::string solve_puzzle(std::string S, std::vector<int> C) {
int N = S.size(), K = C.size();
vector<int> leMost(K, -1);
vector<vector<int>> riMove(K);
FOR(j, K) { // O(N^2K)
int i;
if (j == 0) i = 0;
else i = leMost[j-1]+C[j-1]+1;
while(i <= N-C[j]) {
bool yes = true;
for(int l = i; l < i+C[j]; l++) {
if (S[l] == '_') {
yes = false;
break;
}
}
if (yes && leMost[j] == -1) leMost[j] = i;
else if (yes && leMost[j] != -1) riMove[j].push_back(i-leMost[j]);
i++;
}
}
string validL = S, validR = S;
FOR(j, K) { // O(NK)
FOR(i, C[j]) validL[leMost[j]+i] = 'X';
}
FOR(i, N) if (validL[i] != 'X') validL[i] = '_';
int prL = N+1;
for(int j = K-1; j >= 0; j--) { // O(NK)
int bsf = leMost[j];
for(int r: riMove[j]) {
if (leMost[j] + r + C[j] < prL) bsf = max(bsf, leMost[j] + r);
}
FOR(i, C[j]) validR[bsf+i] = 'X';
prL = bsf;
}
FOR(i, N) if (validR[i] != 'X') validR[i] = '_';
// cout << validL << endl << validR << endl;
string ans;
FOR(i, N) {
if (validL[i] == validR[i]) ans[i] = validL[i];
else ans[i] = '?';
}
return ans;
}
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... |