# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
615698 | ACGN | Paint By Numbers (IOI16_paint) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
const int inf = 1e9;
bool cr(string& s,vi& tg) {
//cout<<s<<endl;
int cs = 0;
int tgp = 0;
for (int i=0;i<s.size();i++) {
if (s[i]=='.') {
cs++;
if (cs==tg[tgp]) {
cs=-1;tgp++;
if (tgp==tg.size()) return 1;
}
}
else cs=0;
}
return 0;
}
vi crfront(string& s,vi& tg) {
int cs = 0;
int tgp = 0;
vi csr(tg.size()+1,inf);
csr[0]=-1;
for (int i=0;i<s.size();i++) {
if (s[i]=='.') {
cs++;
if (cs==tg[tgp]) {
cs=-1;tgp++;csr[tgp]=i+1;
if (tgp==tg.size()) return csr;
}
}
else cs=0;
}
return csr;
}
vi crback(string& s,vi& tg) {
int cs = 0;
int tgp = tg.size()-1;
vi csr(tg.size()+1,-inf);csr[tg.size()]=s.size();
for (int i=s.size()-1;i>=0;i--) {
if (s[i]=='.') {
cs++;
if (cs==tg[tgp]) {
cs=-1;csr[tgp]=i-1;tgp--;
if (tgp==-1) return csr;
}
}
else cs=0;
}
return csr;
}
void solve() {
string s;cin>>s;
int m;cin>>m;
vi v;
int n = s.size();
for (int i=0;i<m;i++) {
int z;cin>>z;
v.pb(z);
}
string s1=s,s2=s,sf=s;
for (int i=0;i<n;i++) {
if (s[i]=='.') {
s1[i]='_';
if (cr(s1,v)) s2[i]='_';
s1[i]='.';
}
}
vi v1=crfront(s,v),v2=crback(s,v);
//for (int i=0;i<=m;i++) cout<<v1[i]<<" ";cout<<endl;
//for (int i=0;i<=m;i++) cout<<v2[i]<<" ";cout<<endl;
for (int i=0;i<n;i++) {
if (s[i]=='_') cout<<'_';
else {
int canw = (s2[i]=='_');
int canb = 0;
for (int j=0;j<m;j++) {
int p1 = v1[j],p2=v2[j+1];
int gr=1;
if (p1>=i) continue;
if (p2<=i) continue;
for (int q=i+1;q<p2;q++) {
if (s[q]=='_') break;
gr++;
}
for (int q=i-1;q>p1;q--) {
if (s[q]=='_') break;
gr++;
}
//cout<<j<<" "<<gr<<endl;
if (gr>=v[j]) canb=2;
}
switch(canb+canw) {
case 1:
cout<<'_';break;
case 2:
cout<<'X';break;
case 3:
cout<<'?';break;
}
}
}
}
signed main() {
solve();
}