Submission #1262155

#TimeUsernameProblemLanguageResultExecution timeMemory
1262155icebearBuilding 4 (JOI20_building4)C++20
11 / 100
65 ms126028 KiB
// ~~ icebear ~~ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; template<class T> bool minimize(T &a, const T &b) { if (a > b) return a = b, true; return false; } template<class T> bool maximize(T &a, const T &b) { if (a < b) return a = b, true; return false; } #define FOR(i,a,b) for(int i=(a); i<=(b); ++i) #define FORR(i,a,b) for(int i=(a); i>=(b); --i) #define REP(i, n) for(int i=0; i<(n); ++i) #define RED(i, n) for(int i=(n)-1; i>=0; --i) #define MASK(i) (1LL << (i)) #define BIT(S, i) (((S) >> (i)) & 1) #define mp make_pair #define pb push_back #define fi first #define se second #define all(x) x.begin(), x.end() #define task "icebear" const int MOD = 1e9 + 7; const int inf = 1e9 + 27092008; const ll INF = 1e18 + 27092008; const int N = 4000 + 5; int n, a[2][N]; int f[N][N][2]; void init(void) { cin >> n; REP(i, 2) FOR(j, 1, 2 * n) cin >> a[i][j]; } void process(void) { memset(f, -1, sizeof f); f[0][0][0] = 0; FOR(i, 0, 2 * n - 1) FOR(j, 0, n) FOR(k, 0, 1) if (~f[i][j][k]) { FOR(t, 0, 1) if (a[t][i + 1] >= a[k][i]) f[i + 1][j + (t == 1)][t] = k; } int t = 2; if (f[2*n][n][0] > -1) t = 0; else if (f[2*n][n][1] > -1) t = 1; if (t == 2) cout << -1; else { int i=2*n, j=n; vector<char> res(2*n); while(i > 0 && j >= 0) { if (j == 0) res[--i] = 'A'; else { res[i-1] = (t == 0 ? 'A' : 'B'); if (t==1) j--; t = f[i][j+(t==1)][t]; i--; } } for(auto &c : res) cout << c; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int tc = 1; // cin >> tc; while(tc--) { init(); process(); } return 0; }

Compilation message (stderr)

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