This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC optimize("O3")*/
#include<bits/stdc++.h>
#include "paint.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#define ordered_set tree<int, null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000000
#define PI 3.14159265358979323846
using namespace std;
string solve_puzzle(string s, vector<int> c)
{
int n=s.length(), k=c.size();
int pr[n+1];
for(int i = 0;i < n+1; i++)
pr[i]=0;
for(int i = s.length()-1; i >= 0; i--)
{
if(s[i]!='_')
pr[i]=1;
pr[i]+=pr[i+1];
}
int dp[n+1][k+1];
for(int i = 0; i < n+1; i++)
for(int j = 0; j < k+1; j++)
dp[i][j]=0;
for(int i = k-1; i >= 0; i--)
dp[n][i]=1+dp[n][i+1];
for(int i = k-1; i >= 0; i--)
{
for(int j = n-1; j >= 0; j--)
{
if(j+c[i]-1 < n && s[j+c[i]-1]!='X' && (j==0 || s[j-1]!='X') && pr[j]-pr[j+c[i]]==0 && dp[j+c[i]][i+1] > 0)
dp[j][i]=1;
dp[j][i]+=dp[j+1][i];
}
}
for(int i = 1; i < k; i++)
{
int sum=0;
for(int j = n-1; j >= 0; j--)
{
int x=dp[j][i];
dp[j][i]=dp[j+1][i];
if(x==sum+1)
{
sum++;
if(j-1-c[i-1] >= 0 && dp[0][i-1]-dp[j-1-c[i-1]+1][i-1] > 0)
dp[j][i]++;
}
}
}
for(int i = 0; i < n; i++)
{
bool done=0;
if(s[i]=='.')
{
for(int j = 0; j < k && !done; j++)
{
int pos=max(0, i-c[j]+1);
if(dp[pos][j]-dp[i+1][j] > 0)
done=1;
}
if(!done)
{
s[i]='_';
}
else
{
done=0;
if(dp[0][k-1]-dp[max(i-c[k-1]+2, 0)][k-1] > 0 || dp[i+1][0]-dp[n][0] > 0)
done=1;
for(int j = 0; j < k-1 && !done; j++)
{
if(dp[0][j]-dp[max(i-c[j]+2, 0)][j] > 0 && dp[i+1][j+1]-dp[n][j+1] > 0)
done=1;
}
if(!done)
{
s[i]='X';
}
else
s[i]='?';
}
}
}
return s;
return "";
}
//size
# | 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... |