Submission #212296

#TimeUsernameProblemLanguageResultExecution timeMemory
212296arnold518Building 4 (JOI20_building4)C++14
11 / 100
7 ms512 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 4000; int N, A[MAXN+10], B[MAXN+10]; int dpl[MAXN+10][2], dpr[MAXN+10][2]; int main() { int i, j, k; scanf("%d", &N); for(i=1; i<=N*2; i++) scanf("%d", &A[i]); for(i=1; i<=N*2; i++) scanf("%d", &B[i]); dpl[1][0]=dpr[1][0]=1; dpl[1][1]=dpr[1][1]=0; for(i=2; i<=N*2; i++) { dpl[i][0]=dpl[i][1]=987654321; dpr[i][0]=dpr[i][1]=-1; if(A[i-1]<=A[i]) { dpl[i][0]=min(dpl[i][0], dpl[i-1][0]+1); dpr[i][0]=max(dpr[i][0], dpr[i-1][0]+1); } if(B[i-1]<=A[i]) { dpl[i][0]=min(dpl[i][0], dpl[i-1][1]+1); dpr[i][0]=max(dpr[i][0], dpr[i-1][1]+1); } if(A[i-1]<=B[i]) { dpl[i][1]=min(dpl[i][1], dpl[i-1][0]); dpr[i][1]=max(dpr[i][1], dpr[i-1][0]); } if(B[i-1]<=B[i]) { dpl[i][1]=min(dpl[i][1], dpl[i-1][1]); dpr[i][1]=max(dpr[i][1], dpr[i-1][1]); } } int p, q=N; if(dpl[2*N][0]<=N && N<=dpr[2*N][0]) p=0; else if(dpl[2*N][1]<=N && N<=dpr[2*N][1]) p=1; else return !printf("-1\n"); vector<int> ans; for(i=2*N; i>=1; i--) { ans.push_back(p); if(p==0) { q--; if(A[i-1]<=A[i] && dpl[i-1][0]<=q && q<=dpr[i-1][0]) p=0; if(B[i-1]<=A[i] && dpl[i-1][1]<=q && q<=dpr[i-1][1]) p=1; } else { if(A[i-1]<=B[i] && dpl[i-1][0]<=q && q<=dpr[i-1][0]) p=0; if(B[i-1]<=B[i] && dpl[i-1][1]<=q && q<=dpr[i-1][1]) p=1; } } reverse(ans.begin(), ans.end()); for(auto it : ans) printf("%c", it ? 'B' : 'A'); printf("\n"); }

Compilation message (stderr)

building4.cpp: In function 'int main()':
building4.cpp:15:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, k;
         ^
building4.cpp:15:12: warning: unused variable 'k' [-Wunused-variable]
  int i, j, k;
            ^
building4.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
building4.cpp:18:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=N*2; i++) scanf("%d", &A[i]);
                        ~~~~~^~~~~~~~~~~~~
building4.cpp:19:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=N*2; i++) scanf("%d", &B[i]);
                        ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...