# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1082231 | laight | Paint By Numbers (IOI16_paint) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pi pair<int, int>
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define umi unordered_map<int, int>
#define umll unordered_map<ll, ll>
#define umllv unordered_map<ll, vector<ll>>
#define getchar() (*_pinp?*_pinp++:(_inp[fread(_pinp=_inp, 1, 4096, stdin)]='\0', *_pinp++))
char _inp[4097], *_pinp=_inp;
#define scan(x) do{while((x=getchar())<'-'); _ssign=x=='-'; if(_ssign) while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
char _; bool _ssign;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std; using namespace __gnu_pbds;
const int MM = 1e5+5;
const int inf = 2e9;
const int mod = 1e9+7;
string s; bool dpl[MM][105], dpr[MM][105]; int prew[MM], n, c, cl[105]; bool wht[MM]; int blk[MM];
int main() {
cin.tie(0); cin.sync_with_stdio(0);
cin >> s >> c; for (int i=0; i<c; i++) cin >> cl[i];
n = (int) s.size(); s.pb('_');
dpl[0][0] = 1; dpr[n+1][c+1] = 1; dpr[n+2][c+1] = 1;
for (int i=1; i<=n+1; i++){ prew[i] = prew[i-1] + (s[i-1] == '_'); }
for (int i=1; i<=n; i++){
if (s[i-1] != 'X') dpl[i][0] = dpl[i-1][0];
for (int j=1; j<=c; j++){
if (s[i-1] != 'X') dpl[i][j] = dpl[i-1][j];
if (s[i] != 'X' && i >= cl[j-1]+(j > 1) && prew[i] == prew[i-cl[j-1]]){
if (i >= cl[j-1]+1 && s[i-cl[j-1]-1] == 'X') continue;
dpl[i][j] |= dpl[i-cl[j-1]-(j>1)][j-1];
}
}
}
for (int i=n; i>=1; i--){
if (s[i-1] != 'X') dpr[i][c+1] = dpr[i+1][c+1];
for (int j=c; j>=1; j--){
if (s[i-1] != 'X') dpr[i][j] = dpr[i+1][j];
if (i+cl[j-1]+(j<c)-1 <= n && prew[i-1] == prew[i+cl[j-1]-1]){
if (i >= 2 && s[i-2] == 'X') continue;
if (i + cl[j-1]-1 <= n && s[i+cl[j-1]-1] == 'X') continue;
dpr[i][j] |= dpr[i+cl[j-1]+(j<c)][j+1];
}
}
}
for (int i=1; i<=n; i++){
for (int j=0; j<=c; j++){
if (dpl[i-1][j] && dpr[i+1][j+1] && s[i] != 'X') {wht[i] = 1;}
}
}
for (int i=1; i<=n; i++){
for (int j=1; j<=c; j++){
if (dpl[i][j] && dpr[i+2][j+1] && dpl[i-cl[j-1]-(j>1)][j-1] && prew[i] == prew[i-cl[j-1]] && s[i] != 'X'){
if (i-cl[j-1]-1>=0 && s[i-cl[j-1]-1] == 'X') continue;
blk[i]++; blk[i-cl[j-1]]--;
}
}
}
for (int i=n; i>=1; i--) blk[i] = blk[i] + blk[i+1];
for (int i=0; i<n; i++){
if (wht[i+1] && blk[i+1]) cout << '?';
else if (wht[i+1]) cout << '_';
else cout << 'X';
}
cout << '\n';
return 0;
}