이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<paint.h>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1e9+7;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
//llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
string solve_puzzle(string s,vector<int>c){
int n=s.size(),m=c.size(),i,j;
s.pub('_');
s.insert(s.begin(),'_');
vector<int>kare(n+2);//いくつの連続区間を用意できるか
for(i=n;i>=0;i--){
if(s[i]=='_'){kare[i]=0;}else{kare[i]=kare[i+1]+1;}
}
vector<vector<bool>>can(m+2,vector<bool>(n+3));
//区間の左端がなににあるか
//Xが取り残されたらだめ
c.insert(c.begin(),0);
c.pub(0);
can[0][0]=true;
vector<vector<bool>>made(m+1,vector<bool>(n+3));
for(int i=1;i<=m+1;i++){
int nag=c[i];
bool ok=false;
for(j=1;j<=n-nag+1;j++){
if(0<=j-c[i-1]-1&&can[i-1][j-c[i-1]-1]){ok=true;}
//okを配列に送る
made[i-1][j-1]=ok;
if(!ok){continue;}
if(s[j-1]=='X'){ok=false;made[i-1][j-1]=ok;continue;}//あっ!つながっちゃう!
if(kare[j]<nag){continue;}
if(s[j+nag]=='X'){continue;}//いやでも繋がってしまう
can[i][j]=true;
}
}
for(j=0;j<n+2;j++){can[m+1][j]=false;}
can[m+1][n+2]=true;
//madeは0~m
/*for(j=0;j<=m;j++){
for(i=1;i<=n;i++){
if(made[j][i]){cerr<<'o';}else{cerr<<'v';}
}
cerr<<endl;
}*/
for(int i=m;i>=0;i--){
int nag=c[i];
bool ok=false;//それまでの整合性
for(j=n-nag+1;j>=1;j--){
if(j+nag+1<=n+2&&can[i+1][j+nag+1]){ok=true;}
if(made[i][j+nag]){made[i][j+nag]=ok;}
if(!ok){can[i][j]=false;continue;}
if(s[j+nag]=='X'){ok=false;if(made[i][j+nag]){made[i][j+nag-1]=ok;}can[i][j]=false;continue;}//あっ!つながっちゃう!
if(!can[i][j]){continue;}
can[i][j]=false;
if(kare[j]<nag){continue;}
if(s[j-1]=='X'){continue;}//いやでも繋がってしまう
can[i][j]=true;
}
}
//madeが全部falseならX
//canが存在しないなら_
//それ以外は?
string ans=s;
ans.era(ans.begin());
ans.pob();
int gen=0;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(can[j][i]){gen++;}
if(i>c[j]&&can[j][i-c[j]]){gen--;}
}
if(0>=gen&&ans[i-1]=='.'){ans[i-1]='_';}
}
for(i=1;i<=n;i++){
if(ans[i-1]!='.'){continue;}
ans[i-1]='X';
for(j=0;j<=m;j++){
if(made[j][i]){ans[i-1]='?';break;}
}
}
/*cerr<<"deed"<<endl;
for(j=1;j<=m;j++){
for(i=1;i<=n;i++){
if(can[j][i]){cerr<<'o';}else{cerr<<'v';}
}
cerr<<endl;
}
cerr<<"deed"<<endl;
for(j=0;j<=m;j++){
for(i=1;i<=n;i++){
if(made[j][i]){cerr<<'o';}else{cerr<<'v';}
}
cerr<<endl;
}*/
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... |