제출 #659422

#제출 시각아이디문제언어결과실행 시간메모리
659422Ronin13건물 4 (JOI20_building4)C++14
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back #define ull unsigned ll using namespace std; pii merg(pii a, pii b){ return {min(a.f, b.f), max(a.s, b.s)}; } int main(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // ONLINE_JUDGE int n; cin >> n; int a[2 * n + 1][2]; for(int j = 0; j < 2; j++){ for(int i = 1; i <= 2 * n; i++) cin >> a[i][j]; } pii dp[2 * n + 1][2]; dp[1][0] = {0, 0}; dp[1][1] = {1, 1}; for(int i = 2; i <= 2 * n; i++){ for(int j = 0; j < 2; j++){ pii x = {1e9, -1e9}; pii y = {1e9, -1e9}; if(a[i][j] >= a[i - 1][0]){ x = {dp[i - 1][0].f + j, dp[i - 1][0].s + j}; } if(a[i][j] >= a[i - 1][1]){ y = {dp[i - 1][1].f + j, dp[i - 1][1].s + j}; } dp[i][j] = merg(x, y); } } /*for(int i = 1; i <= 2 * n; i++){ for(int j = 0; j < 2; j++){ cout << dp[i][j].f << ' ' << dp[i][j].s << " "; } cout << "\n"; }*/ int last; int cur = n; string ans = ""; if(dp[2 * n][0].f > n || dp[2 * n][0].s < n){ if(dp[2 * n][1].f > n || dp[2 * n][1].s < n){ cout << -1 << "\n"; return 0; } last = 1; cur--; ans += 'B'; } else{ last = 0; ans += 'A'; } for(int i = 2 * n - 1; i >= 1; i--){ for(int j = 0; j < 2; j++){ if(a[i][j] > a[i + 1][last]) continue; if(dp[i][j].f <= cur && dp[i][j].s >= cur){ last = j; cur -= j; break; } } if(last) ans += 'B'; else ans += 'A'; } reverse(ans.begin(), ans.end()); cout << ans; }

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

building4.cpp: In function 'int main()':
building4.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
building4.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...