# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
131521 | mahmoudbadawy | Paint By Numbers (IOI16_paint) | C++17 | 2057 ms | 98740 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 "paint.h"
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
string ss;
vector<int> arr;
int n,k;
int ok[2*100005];
int ansb[2*100005],answ[2*100005];
int mem[2*100005][105];
string ans;
int go(int ind,int ind2)
{
if(ind>=n&&ind2>=k)
return 1;
if(ind>=n)
return 0;
if(mem[ind][ind2]!=-1)
return mem[ind][ind2];
if(ind2>=k)
{
if(ss[ind]=='X')
return mem[ind][ind2]=0;
bool ok=go(ind+1,ind2);
if(ok) answ[ind]++;
return mem[ind][ind2]=ok;
}
bool okk=0;
if(ind+arr[ind2]<=n&&ok[ind+arr[ind2]]-ok[ind]==arr[ind2]&&(ind+arr[ind2]>=n||ss[ind+arr[ind2]]!='X'))
{
bool ok2=go(ind+arr[ind2]+1,ind2+1);
if(ok2)
{
ansb[ind]++;
answ[ind+arr[ind2]]++;
ansb[ind+arr[ind2]]--;
}
okk|=ok2;
}
if(ss[ind]!='X')
{
bool ok2=go(ind+1,ind2);
if(ok2)
answ[ind]++;
okk|=ok2;
}
return mem[ind][ind2]=okk;
}
std::string solve_puzzle(std::string s, std::vector<int> c) {
ss=s; arr=c;
n=s.size();
k=c.size();
ans=string(n,'?');
int i,j;
for(i=0;i<=n;i++)
for(j=0;j<=k;j++)
mem[i][j]=-1;
for(i=1;i<=n;i++)
{
ok[i]=(s[i-1]=='X'||s[i-1]=='.');
ok[i]+=ok[i-1];
}
go(0,0);
for(i=1;i<s.size();i++)
{
ansb[i]+=ansb[i-1];
}
for(i=0;i<n;i++)
{
if(ansb[i]&&answ[i])
ans[i]='?';
else if(ansb[i])
ans[i]='X';
else
ans[i]='_';
}
return ans;
}
Compilation message (stderr)
# | 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... |