제출 #561164

#제출 시각아이디문제언어결과실행 시간메모리
561164Bill_00건물 4 (JOI20_building4)C++14
100 / 100
282 ms29172 KiB
#include <bits/stdc++.h> #define N 500005 #define ff first #define ss second #define ll long long const ll MAXN = 1e9; using namespace std; int n, a[2 * N], b[2 * N]; pair<int, int> dp[2 * N][2]; char x[2 * N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= 2 * n; i++){ cin >> a[i]; } for(int i = 1; i <= 2 * n; i++){ cin >> b[i]; } dp[1][1] = {1, 1}; dp[1][0] = {0, 0}; for(int i = 2; i <= 2 * n; i++){ dp[i][1] = {1e9, -1}; dp[i][0] = {1e9, -1}; if(a[i] >= a[i - 1]){ dp[i][1].ff = min(dp[i][1].ff, dp[i - 1][1].ff + 1); dp[i][1].ss = max(dp[i][1].ss, dp[i - 1][1].ss + 1); } if(a[i] >= b[i - 1]){ dp[i][1].ff = min(dp[i][1].ff, dp[i - 1][0].ff + 1); dp[i][1].ss = max(dp[i][1].ss, dp[i - 1][0].ss + 1); } if(b[i] >= a[i - 1]){ dp[i][0].ff = min(dp[i][0].ff, dp[i - 1][1].ff); dp[i][0].ss = max(dp[i][0].ss, dp[i - 1][1].ss); } if(b[i] >= b[i - 1]){ dp[i][0].ff = min(dp[i][0].ff, dp[i - 1][0].ff); dp[i][0].ss = max(dp[i][0].ss, dp[i - 1][0].ss); } } // for(int i = 1; i <= 2 * n; i++){ // cout << dp[i][1].ff << ' ' << dp[i][1].ss << '\n'; // cout << dp[i][0].ff << ' ' << dp[i][0].ss << '\n'; // } if(dp[2 * n][0].ff <= n && n <= dp[2 * n][0].ss || dp[2 * n][1].ff <= n && n <= dp[2 * n][1].ss){ int lol = n; deque<char> ans; for(int i = 2 * n; i >= 1; i--){ if(dp[i][1].ff <= lol && lol <= dp[i][1].ss){ if(ans.size() > 0){ if(ans.front() == 'A'){ if(a[i] > a[i + 1]){ ans.push_front('B'); continue; } } else{ if(a[i] > b[i + 1]){ ans.push_front('B'); continue; } } } ans.push_front('A'); lol--; } else{ ans.push_front('B'); } } for(char x : ans) cout << x; } else cout << -1; }

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

building4.cpp: In function 'int main()':
building4.cpp:53:29: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   53 |     if(dp[2 * n][0].ff <= n && n <= dp[2 * n][0].ss || dp[2 * n][1].ff <= n && n <= dp[2 * n][1].ss){
      |                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...