Submission #211708

#TimeUsernameProblemLanguageResultExecution timeMemory
211708nvmdavaBuilding 4 (JOI20_building4)C++17
100 / 100
389 ms44536 KiB
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define ll long long #define ff first #define ss second #define N 1050000 #define MOD 998244353 #define INF 0x3f3f3f3f int a[N][2]; int dp[N][2][2]; void update(int i, int j, int mn, int mx){ if(mx == -1) return; if(dp[i][j][0] == -1){ dp[i][j][0] = mn + j; dp[i][j][1] = mx + j; return; } dp[i][j][0] = min(dp[i][j][0], mn + j); dp[i][j][1] = max(dp[i][j][1], mx + j); } int ans[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i = 1; i <= n * 2; ++i) cin>>a[i][0]; for(int i = 1; i <= n * 2; ++i) cin>>a[i][1]; memset(dp, -1, sizeof dp); memset(dp[0], 0, sizeof dp[0]); for(int i = 1; i <= n * 2; ++i){ for(int j0 = 0; j0 < 2; ++j0){ for(int j1 = 0; j1 < 2; ++j1){ if(a[i][j1] >= a[i - 1][j0]) update(i, j1, dp[i - 1][j0][0], dp[i - 1][j0][1]); } } } int la = -1, c = n; if(dp[2 * n][0][0] <= c && c <= dp[2 * n][0][1]) la = 0; if(dp[2 * n][1][0] <= c && c <= dp[2 * n][1][1]) la = 1; if(la == -1){ cout<<-1; return 0; } for(int i = n * 2; i >= 0; --i){ ans[i] = la; c -= la; for(int j = 0; j < 2; ++j){ if(a[i - 1][j] <= a[i][la]){ if(dp[i - 1][j][0] <= c && c <= dp[i - 1][j][1]){ la = j; break; } } } } for(int i = 1; i <= 2 * n; ++i) cout<<(ans[i] == 0 ? "A" : "B"); }

Compilation message (stderr)

building4.cpp: In function 'int main()':
building4.cpp:49:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(dp[2 * n][0][0] <= c && c <= dp[2 * n][0][1])
     ^~
building4.cpp:52:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     if(dp[2 * n][1][0] <= c && c <= dp[2 * n][1][1])
     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...