# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
774003 | Amylopectin | Paint By Numbers (IOI16_paint) | C++14 | 8 ms | 8916 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 <string>
#include <cstdlib>
using namespace std;
const int mxn = 210;
int m,n,c[mxn] = {},dp[mxn][mxn][mxn][2] = {},ru,fr[mxn],to[mxn] = {};
string ans,pate;
int ad(int cn,string cad)
{
if(ans[cn] != '?')
{
if(ans[cn] == '0')
{
ans[cn] = cad[0];
}
else if(ans[cn] != cad[0])
{
ans[cn] = '?';
}
}
return 0;
}
int re(int cn,int ch,int cbl,int tog)
{
if(cn == n && ch== m && cbl == 0)
{
return 1;
}
if(cn >= n)
{
return 0;
}
if(dp[cn][ch][cbl][tog] != -1)
{
return dp[cn][ch][cbl][tog];
}
int i,j,cm,fn,fm,of = 0,ret;
if(cbl == 0 && pate[cn] != 'X')
{
ret = re(cn+1,ch,cbl,0);
of |= ret;
if(ret == 1)
{
ad(cn,"_");
}
}
if(pate[cn] != '_' && pate[cn+1] != 'X')
{
if(cbl+1 == c[ch] && tog == 0)
{
ret = re(cn+1,ch+1,0,1);
of |= ret;
if(ret == 1)
{
ad(cn,"X");
}
}
}
if(pate[cn] != '_' && ch < m && cbl < c[ch]-1 && tog == 0)
{
// else
{
ret = re(cn+1,ch,cbl+1,0);
of |= ret;
if(ret == 1)
{
ad(cn,"X");
}
}
}
// if(of == 1)
// {
// if(cbl == 0)
// {
// ad(cn,"_");
// }
// else
// {
// ad(cn,"X");
// }
// }
dp[cn][ch][cbl][tog] = of;
return of;
}
std::string solve_puzzle(std::string s, std::vector<int> cc)
{
int i,j,k,be;
string fa;
pate = s;
n = s.size();
m = cc.size();
for(i=0; i<m; i++)
{
c[i] = cc[i];
}
ru = 0;
be = 0;
for(i=0; i<n; i++)
{
ans.push_back('0');
}
// for(i=0; i<n-1; i++)
// {
// if(s[i] == '_')
// {
// ans[i] = '_';
// }
// if(s[i]!= s[i+1])
// {
// if(s[i] == '.')
// {
// fr[ru] = be;
// to[ru] = i;
// ru++;
// }
// else
// {
// be = i+1;
// }
// }
// }
// if(s[n-1] == '_')
// {
// ans[n-1] = '_';
// }
// if(s[n-1] == '.')
// {
// fr[ru] = be;
// to[ru] = n-1;
// ru++;
// }
for(i=0; i<n; i++)
{
for(j=0; j<=m; j++)
{
for(k=0; k<=c[j]; k++)
{
dp[i][j][k][0] = -1;
dp[i][j][k][1] = -1;
}
}
}
// for(j=0; j<n; j++)
// {
// dp[ru][j] = 0;
// }
dp[n][m][0][0] = 1;
dp[n][m][0][1] = 1;
re(0,0,0,0);
// if(s[0] == '_' || s[0] == '.')
// {
// // re(0,0,0);
// }
// if(s[0] == 'X' || s[0] == '.')
// {
// re(0,0,1);
// }
// ans = cal(0,m-1,n);
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... |