#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include "paint.h"
using namespace std;
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define ll long long
#define ld long double
#define ui uint64_t
#define cont(set, element) ((set).find(element) != (set).end())
/********* DEBUG *********/
template <typename T>
void outvec(const vector<T>& Z){
for (const T& x : Z)
cout << x << ' ';
cout << "\n";
}
void printVariable(const any& var) {
if (!var.has_value()) {
cout << "null";
return;
}
if (var.type() == typeid(int)) {
cout << any_cast<int>(var);
} else if (var.type() == typeid(double)) {
cout << any_cast<double>(var);
} else if (var.type() == typeid(float)) {
cout << any_cast<float>(var);
} else if (var.type() == typeid(char)) {
cout << any_cast<char>(var);
} else if (var.type() == typeid(bool)) {
cout << (any_cast<bool>(var) ? "true" : "false");
} else if (var.type() == typeid(string)) {
cout << any_cast<string>(var);
} else if (var.type() == typeid(const char*)) {
cout << any_cast<const char*>(var);
} else if (var.type() == typeid(long long)) {
cout << any_cast<long long>(var);
} else {
cout << "[unknown type]";
}
}
template<typename... Args>
void outval(Args... args) {
vector<any> variables = {args...};
for (size_t i = 0; i < variables.size(); ++i) {
printVariable(variables[i]);
if (i != variables.size() - 1) {
cout << " ";
}
}
cout << "\n";
}
#define nl "\n"
#define sp << " " <<
/********* DEBUG *********/
const ll MOD = 1000000007;
const ll inf = 1e18;
const ll mxN = 1000005;
string solve_puzzle(string s, vector<int> c) {
ll n = sz(s);
ll k = sz(c);
vector<ll> pref(n+1);
for (int i = 0; i < n; i++){
pref[i+1]=pref[i]+(s[i]=='_');
}
// {first i cells, first j clues}
vector<vector<bool>> dp1(n+1, vector<bool>(k+1, false)), dp2 = dp1;
dp1[0][0] = dp2[n][k] = true;
for (int i = 0; i < n; i++){
for (int j = 0; j <= k; j++){
if (s[i] != 'X')
dp1[i+1][j] = dp1[i][j] | dp1[i+1][j];
if (j < k && i + c[j] < n && s[i+c[j]] != 'X' && pref[i] == pref[i+c[j]])
dp1[i+c[j]+1][j+1] = dp1[i][j] | dp1[i+c[j]+1][j+1];
}
}
for (int i = n; i; i--){
for (int j = 0; j <= k; j++){
if (s[i-1] != 'X')
dp2[i-1][j] = dp2[i][j] | dp2[i-1][j];
if (j && i - c[j-1] > 0 && s[i-c[j-1]-1] != 'X' && pref[i] == pref[i-c[j-1]])
dp2[i-c[j-1]-1][j-1] = dp2[i][j] | dp2[i-c[j-1]-1][j-1];
}
}
vector<ll> black(n+1);
for (int i = 0; i < n; i++){
bool white = false;
for (int j = 0; j <= k; j++){
white |= dp1[i+1][j] && dp2[i][j];
}
for (int j = 0; j < k; j++){
if (i + c[j] <= n && dp1[i][j] && dp2[i+c[j]][j+1] && pref[i] == pref[i+c[j]]){
black[i]++;
black[i+c[j]]--;
}
}
black[i+1] += black[i];
s[i] = (white && black[i] ? '?' : white ? '_' : 'X');
}
return s;
}
컴파일 시 표준 에러 (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... |