Submission #1164381

#TimeUsernameProblemLanguageResultExecution timeMemory
1164381hainam2k9Building 4 (JOI20_building4)C++20
11 / 100
154 ms24012 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 1e6+5; const string NAME = ""; int n; bool dp[4005][2005][2]; pair<int,int> p[MAXN]; vector<char> v; int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n; for(int i = 1; i<=n<<1; ++i) cin >> p[i].fi; for(int i = 1; i<=n<<1; ++i) cin >> p[i].se; dp[1][0][0]=dp[1][1][1]=1; for(int i = 2; i<=n<<1; ++i) for(int j = 0; j<=min(i,n); ++j){ dp[i][j][0]|=dp[i-1][j][0]&(p[i].fi>=p[i-1].fi); dp[i][j][0]|=dp[i-1][j][1]&(p[i].fi>=p[i-1].se); dp[i][j][1]|=dp[i-1][j-1][0]&(p[i].se>=p[i-1].fi); dp[i][j][1]|=dp[i-1][j-1][1]&(p[i].se>=p[i-1].se); } if(!dp[n<<1][n][0]&&!dp[n<<1][n][1]) return cout << -1, 0; for(int i=n<<1, cnt=n; i>0; --i){ if(dp[i][cnt][0]&&(i==2*n||p[i].fi<=(v.back()=='A' ? p[i+1].fi : p[i+1].se))) v.pb('A'); else v.pb('B'), --cnt; } reverse(v.begin(),v.end()); for(char& c : v) cout << c; }

Compilation message (stderr)

building4.cpp: In function 'int main()':
building4.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
building4.cpp:29:45: note: in expansion of macro 'fo'
   29 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
building4.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
building4.cpp:29:45: note: in expansion of macro 'fo'
   29 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...