제출 #211754

#제출 시각아이디문제언어결과실행 시간메모리
211754nafis_shifat건물 4 (JOI20_building4)C++14
100 / 100
1288 ms34920 KiB
#include<bits/stdc++.h> #define pii pair<int,int> #define ll long long using namespace std; int main() { int n; cin>>n; int dp1[2*n+1][2]={}; int dp2[2*n+1][2]={}; for(int i=0;i<=2*n;i++)dp1[i][0]=dp1[i][1]=1e9+9; memset(dp2,-1,sizeof(dp2)); int a[2*n+1],b[2*n+1]; for(int i=1;i<=2*n;i++)cin>>a[i]; for(int i=1;i<=2*n;i++)cin>>b[i]; dp1[1][0]=dp2[1][0]=1; dp1[1][1]=dp2[1][1]=0; for(int i=2;i<=2*n;i++) { if(a[i-1]<=a[i]) { dp1[i][0]=dp1[i-1][0]+1; dp2[i][0]=dp2[i-1][0]+1; } if(b[i-1]<=a[i]) { dp1[i][0]=min(dp1[i][0],dp1[i-1][1]+1); dp2[i][0]=max(dp2[i][0],dp2[i-1][1]+1); } if(a[i-1]<=b[i]) { dp1[i][1]=dp1[i-1][0]; dp2[i][1]=dp2[i-1][0]; } if(b[i-1]<=b[i]) { dp1[i][1]=min(dp1[i][1],dp1[i-1][1]); dp2[i][1]=max(dp2[i][1],dp2[i-1][1]); } } // cout<<dp2[2*n][0]<<endl; int cr=2*n; int nx=0; int tx=n; vector<int> r; if(dp1[cr][0]<=n && dp2[cr][0]>=n) { r.push_back(0); tx--; if(dp1[cr-1][0]<=tx && dp2[cr-1][0]>=tx && a[cr-1]<=a[cr])nx=0; else nx=1; } else if(dp1[cr][1]<=n && dp2[cr][1]>=n) { r.push_back(1); if(dp1[cr-1][0]<=n && dp2[cr-1][0]>=n && a[cr-1]<=b[cr])nx=0; else nx=1; } else { cout<<-1<<endl; return 0; } cr--; while(cr) { r.push_back(nx); if(nx==0 && tx>0) { tx--; if(dp1[cr-1][0]<=tx && dp2[cr-1][0]>=tx && a[cr-1]<=a[cr])nx=0; else nx=1; cr--; continue; } else { if(dp1[cr-1][0]<=tx && dp2[cr-1][0]>=tx && a[cr-1]<=b[cr])nx=0; else nx=1; cr--; continue; } } reverse(r.begin(),r.end()); for(int i=0;i<r.size();i++) { if(r[i]==0)cout<<"A"; else cout<<"B"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

building4.cpp: In function 'int main()':
building4.cpp:118:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<r.size();i++)
                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...