이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define N 200005
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("in.txt","r",stdin);freopen ("out.txt","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
#include "paint.h"
using namespace std;
ll n,m,ar[N],sum,t,tut[N],tree[6*N],tutb[N],lazy[6*N],pref[N],flag,tutmac[N];
ll dp[200100][150];
string att,sss;
ll f(int ind,int k)
{
if(ind>n)
return 0;
if(ind==n && k==m)
{
// cerr<<"hello"<<endl;
return 1;
}
if(k>m)
return 0;
if(ind==n)
return 0;
// cerr<<ind<<sp<<k<<endl;
if(dp[ind][k]!=-1)
return dp[ind][k];
ll a=0;
if(sss[ind]!='X')
a=f(ind+1,k);
a=min(a,1ll);
ll x=0;
ll b=0;
if(ind>0)
x=pref[ind-1];
if(ind+ar[k]<=n && pref[ind+ar[k]-1]-x==0 && sss[ind+ar[k]]!='X' && sss[ind]!='_')
{
if(ind+ar[k]==n)
b=f(ind+ar[k],k+1);
else
b=f(ind+ar[k]+1,k+1);
}
b=min(1ll,b);
// cout<<ind<<sp<<k<<sp<<a<<sp<<b<<endl;
if(sss[ind]=='_')
{
tutb[ind]=max(tutb[ind],a);
return dp[ind][k]=a;
}
if(b)
tutb[ind+ar[k]]=max(tutb[ind],1ll);
if(sss[ind]=='X')
{
// updateRange(1,0,n-1,ind,ind+ar[k]-1,b);
// upd(1,0,n-1,ind,ind+ar[k]-1,b);
if(b)
tutmac[ind]=max(tutmac[ind],ar[k]);
return dp[ind][k]=b;
}
tutb[ind]=max(tutb[ind],a);
// cout<<ind<<sp<<k<<sp<<a<<sp<<b<<endl;
// if(b)
// cout<<"X"<<sp<<ind<<sp<<k<<endl;
// if(a)
// cout<<"_"<<sp<<ind<<sp<<k<<endl;
if(b)
tutmac[ind]=max(tutmac[ind],ar[k]);
// updateRange(1,0,n-1,ind,ind+ar[k]-1,b);
// upd(1,0,n-1,ind,ind+ar[k]-1,b);
if(ind==0 && b)
flag=1;
return dp[ind][k]=max(a,b);
}
string solve_puzzle(string ss,vector<int> c)
{
m=c.size();
fo(i,0,m-1)
ar[i]=c[i];
n=ss.size();
sss=ss;
memset(dp,-1,sizeof(dp));
fo(i,0,n)
{
pref[i]=pref[i-1];
if(sss[i]=='_')
pref[i]++;
}
f(0,0);
att.clear();
ll flag=0;
// fo(i,0,n-1)
// cout<<tutmac[i];
// cout<<endl;
// // ll flag=0;
// fo(i,0,n-1)
// cout<<tutb[i];
// cout<<endl;
fo(i,0,n-1)
{
// ll x=query(1,0,n-1,i);
ll x=0;
flag=max(flag,tutmac[i]);
if(flag>=1)
x=1;
flag--;
if(flag<0)
flag=0;
ll y=tutb[i];
if(x && !y)
att.pb('X');
if(!x && y)
att.pb('_');
if(att.size()!=i+1)
att.pb('?');
}
// char a='0'+queryRange(1,0,n-1,0,0);
// char a='0'+query(1,0,n-1,0);
// cout<<queryRange(1,0,n-1,0,0)<<sp;
// cout<<query(1,0,n-1,0)<<endl;
// string b;
// b.pb(a);
// fo(i,1,12)
// b.pb('a');
// cout<<ar[0]<<endl;;
// return b;
// return "?????XXX?????";
// char x='0'+tutmac[0];
// if(ar[0]==1559)
// att[0]=x;
return att;
}
// #include "paint.h"
// #include <vector>
// #include <string>
// #include <cstdio>
// #include <cassert>
// const int S_MAX_LEN = 200 * 1000;
// char buf[S_MAX_LEN + 1];
// int main() {
// fast2;
// assert(1 == scanf("%s", buf));
// std::string s = buf;
// int c_len;
// assert(1 == scanf("%d", &c_len));
// std::vector<int> c(c_len);
// for (int i = 0; i < c_len; i++) {
// assert(1 == scanf("%d", &c[i]));
// }
// std::string ans = solve_puzzle(s, c);
// printf("%s\n", ans.data());
// return 0;
// }
컴파일 시 표준 에러 (stderr) 메시지
paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:137:16: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
137 | if(att.size()!=i+1)
| ~~~~~~~~~~^~~~~
# | 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... |