#include <bits/stdc++.h>
using namespace std;
#define oo 1e15
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
typedef pair<pair<long long,long long>,pair<long long,long long>> pllll;
typedef pair<pair<long long,long long>,bool> pllb;
const ll base=361;
const ll mod=1e9+7;
const ld eps=1e-5;
const ll maxn=1e7-1;
ll n,i,a[500009],b[500009],f[5009][5009][4],j;
void Trace(ll x,ll y,ll msk) {
if (x==0) {
return;
}
if (msk==1) {
if (f[x-1][y-1][0]&&b[x]>=a[x-1]) {
Trace(x-1,y-1,0);
}
else {
Trace(x-1,y-1,1);
}
cout<<'B';
}
else {
if (f[x-1][y][0]&&a[x]>=a[x-1]) {
Trace(x-1,y,0);
}
else {
Trace(x-1,y,1);
}
cout<<'A';
}
}
int main(){
IO;
cin>>n;
for (i=1;i<=2*n;i++) {
cin>>a[i];
}
for (i=1;i<=2*n;i++) {
cin>>b[i];
}
if (n<=2000) {
f[0][0][1]=true;
f[0][0][0]=true;
for (i=1;i<=2*n;i++) {
for (j=0;j<=n;j++) {
if (a[i]>=a[i-1]) {
f[i][j][0]|=f[i-1][j][0];
}
if (a[i]>=b[i-1]) {
f[i][j][0]|=f[i-1][j][1];
}
if (b[i]>=a[i-1]) {
f[i][j][1]|=f[i-1][j-1][0];
}
if (b[i]>=b[i-1]) {
f[i][j][1]|=f[i-1][j-1][1];
}
}
}
if (f[2*n][n][0]) {
Trace(2*n,n,0);
}
else if (f[2*n][n][1]) {
Trace(2*n,n,1);
}
else {
cout<<-1;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
130 ms |
192236 KB |
Output is correct |
6 |
Correct |
125 ms |
218476 KB |
Output is correct |
7 |
Correct |
104 ms |
173164 KB |
Output is correct |
8 |
Correct |
121 ms |
199916 KB |
Output is correct |
9 |
Correct |
119 ms |
209004 KB |
Output is correct |
10 |
Correct |
101 ms |
168684 KB |
Output is correct |
11 |
Correct |
133 ms |
236780 KB |
Output is correct |
12 |
Correct |
157 ms |
267884 KB |
Output is correct |
13 |
Correct |
178 ms |
267884 KB |
Output is correct |
14 |
Correct |
156 ms |
267884 KB |
Output is correct |
15 |
Correct |
157 ms |
268012 KB |
Output is correct |
16 |
Correct |
153 ms |
267756 KB |
Output is correct |
17 |
Correct |
153 ms |
267428 KB |
Output is correct |
18 |
Correct |
153 ms |
267884 KB |
Output is correct |
19 |
Correct |
171 ms |
267872 KB |
Output is correct |
20 |
Correct |
151 ms |
268012 KB |
Output is correct |
21 |
Correct |
157 ms |
267884 KB |
Output is correct |
22 |
Correct |
156 ms |
267884 KB |
Output is correct |
23 |
Correct |
157 ms |
267884 KB |
Output is correct |
24 |
Correct |
154 ms |
267960 KB |
Output is correct |
25 |
Correct |
148 ms |
265196 KB |
Output is correct |
26 |
Correct |
156 ms |
268012 KB |
Output is correct |
27 |
Correct |
151 ms |
267884 KB |
Output is correct |
28 |
Correct |
123 ms |
216044 KB |
Output is correct |
29 |
Correct |
156 ms |
267940 KB |
Output is correct |
30 |
Correct |
126 ms |
217708 KB |
Output is correct |
31 |
Correct |
150 ms |
267884 KB |
Output is correct |
32 |
Correct |
109 ms |
190572 KB |
Output is correct |
33 |
Correct |
152 ms |
267884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
130 ms |
192236 KB |
Output is correct |
6 |
Correct |
125 ms |
218476 KB |
Output is correct |
7 |
Correct |
104 ms |
173164 KB |
Output is correct |
8 |
Correct |
121 ms |
199916 KB |
Output is correct |
9 |
Correct |
119 ms |
209004 KB |
Output is correct |
10 |
Correct |
101 ms |
168684 KB |
Output is correct |
11 |
Correct |
133 ms |
236780 KB |
Output is correct |
12 |
Correct |
157 ms |
267884 KB |
Output is correct |
13 |
Correct |
178 ms |
267884 KB |
Output is correct |
14 |
Correct |
156 ms |
267884 KB |
Output is correct |
15 |
Correct |
157 ms |
268012 KB |
Output is correct |
16 |
Correct |
153 ms |
267756 KB |
Output is correct |
17 |
Correct |
153 ms |
267428 KB |
Output is correct |
18 |
Correct |
153 ms |
267884 KB |
Output is correct |
19 |
Correct |
171 ms |
267872 KB |
Output is correct |
20 |
Correct |
151 ms |
268012 KB |
Output is correct |
21 |
Correct |
157 ms |
267884 KB |
Output is correct |
22 |
Correct |
156 ms |
267884 KB |
Output is correct |
23 |
Correct |
157 ms |
267884 KB |
Output is correct |
24 |
Correct |
154 ms |
267960 KB |
Output is correct |
25 |
Correct |
148 ms |
265196 KB |
Output is correct |
26 |
Correct |
156 ms |
268012 KB |
Output is correct |
27 |
Correct |
151 ms |
267884 KB |
Output is correct |
28 |
Correct |
123 ms |
216044 KB |
Output is correct |
29 |
Correct |
156 ms |
267940 KB |
Output is correct |
30 |
Correct |
126 ms |
217708 KB |
Output is correct |
31 |
Correct |
150 ms |
267884 KB |
Output is correct |
32 |
Correct |
109 ms |
190572 KB |
Output is correct |
33 |
Correct |
152 ms |
267884 KB |
Output is correct |
34 |
Incorrect |
164 ms |
8172 KB |
Unexpected end of file - token expected |
35 |
Halted |
0 ms |
0 KB |
- |