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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int n,m;
const int N=2e5+5;
int sum[N][2],cnt[2];
int getSum(int l,int r,int x)
{
int sol=sum[r][x];
if(l)
sol-=sum[l-1][x];
return sol;
}
vector<int> k;
vector<pair<pair<int,int>,int> > e;
short dp[N][101][2];
bool calc(int tr,int i,bool imam)
{
if(tr==n)
return i==m;
if(dp[tr][i][imam]!=-1)
return dp[tr][i][imam];
dp[tr][i][imam]=0;
if(imam&&i<m&&n-tr>=k[i]&&getSum(tr,tr+k[i]-1,1)==0)
if(calc(tr+k[i],i+1,0))
dp[tr][i][imam]=1,e.pb({{tr,1},1}),e.pb({{tr+k[i],-1},1});
if(getSum(tr,tr,0)==0)
if(calc(tr+1,i,1))
dp[tr][i][imam]=1,e.pb({{tr,1},0}),e.pb({{tr+1,-1},0});
return dp[tr][i][imam];
}
string solve_puzzle(string s,vector<int> c)
{
memset(dp,-1,sizeof(dp));
k=c;
n=s.size();
m=c.size();
for(int i=0;i<n;i++)
{
if(s[i]=='X')
sum[i][0]++;
if(s[i]=='_')
sum[i][1]++;
if(i)
sum[i][0]+=sum[i-1][0],sum[i][1]+=sum[i-1][1];
}
calc(0,0,1);
string ans;
sort(all(e));
e.pb({{n,n},n});
int j=0;
for(int i=0;i<n;i++)
{
while(e[j].f.f==i)
cnt[e[j].s]+=e[j].f.s,j++;
if(cnt[0]==0)
ans+='X';
if(cnt[1]==0)
ans+='_';
if(cnt[0]!=0&&cnt[1]!=0)
ans+='?';
}
return ans;
}
# | 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... |