이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include <ext/rope>
using namespace __gnu_cxx;
// #pragma comment(linker, "/stack:2000000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define precise(a) cout<<fixed<<setprecision(a)
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
// t1
const ll mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const ll N = ll(5e5)+10;
const ll K = 17;
const ll inf = 1e18;
const ld eps = 1e-15L;
//const ll B = 316;
ll lcm(ll a, ll b){ return (a / __gcd(a,b)) * b; }
//const ld P = acos(-1.0);
// ll binpow(ll a, ll b, ll m){ ll res=1;a%=m; while(b>0){ if(b&1)res=(res*a)%m; a=(a*a)%m; b/=2; } return res%m;}
ld binpow(ld a, ll b){ ld res=1; while(b>0){ if(b&1)res=(res*a); a=(a*a); b/=2; } return res;}
void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
void precalc() {
}
void Baizho()
{
ll n; cin>>n;
ll n1 = n*2;
ll dp[n1+2][n1+2], a[n1+2], b[n1+2];
for(ll i=1; i<=n1; i++) cin>>a[i];
for(ll i=1; i<=n1; i++) cin>>b[i];
for(ll i=0; i<=n1; i++) for(ll j=0; j<=n1; j++) dp[i][j] = inf;
dp[0][0] = -1;
for(ll i=1; i<=n1; i++) {
for(ll j=0; j<=min(n-1, i-1); j++) {
// getA
ll A = j, B = i-1-j;
if(dp[A][B]<=a[i]) {
dp[A+1][B] = min(dp[A+1][B], a[i]);
}
// getB
A = i-1-j, B = j;
if(dp[A][B]<=b[i]) {
dp[A][B+1] = min(dp[A][B+1], b[i]);
}
}
}
if(dp[n][n]==inf) cout<<"-1\n";
else {
ll i = n, j = n, anspos = n1;
string ans;
while(i || j) {
// cout<<dp[i][j]<<" "<<i<<" "<<j<<endl;
if(dp[i][j]==a[anspos] && i) {
ans = "A" + ans;
i--;
}
else {
ans = "B" + ans;
j--;
}
anspos--;
}
cout<<ans;
}
}
int main() {
// Freopen("div7");
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
precalc();
int ttt = 1;
// cin>>ttt;
for(int i=1; i<=ttt; i++) { Baizho();}
}
컴파일 시 표준 에러 (stderr) 메시지
building4.cpp: In function 'void Freopen(std::string)':
building4.cpp:37:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
building4.cpp:37:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |