ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215375 | #2777. 2048 | nodgd | 70 | 82ms | 19560kb | C++11 | 4.1kb | 2024-11-28 21:56:34 | 2024-11-28 23:13:42 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int BUFFER_SIZE = 1 << 20;
char rb[BUFFER_SIZE], *rp = rb, *rt = rb;
inline char read_char() {
return rp == rt ? (rt = rb + fread(rb, 1, BUFFER_SIZE, stdin), rp = rb, *rp ++) : *rp ++;
}
inline i64 read_int() {
i64 x = 0;
char ch = read_char(), flag = 0;
while (ch != '-' && (ch < '0' || ch > '9')) {
ch = read_char();
}
if (ch == '-') {
flag = 1;
ch = read_char();
}
for (x = 0; ch >= '0' && ch <= '9'; ch = read_char()) {
x = x * 10 + (ch - '0');
}
return flag ? -x : x;
}
const int MAX_N = 1000 + 5;
const int MAX_A = 1 << 13 | 5;
int N;
int a[MAX_N], sa[MAX_N];
bitset<MAX_A> f[MAX_N];
short fj[MAX_N][MAX_A];
char fc[MAX_N][MAX_A];
char ans[MAX_N];
int lowbit(int x) {
return x & -x;
}
int highbit(int x) {
return x ? 1 << 31 - __builtin_clz(x) : 0;
}
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i ++) {
scanf("%d", &a[i]);
sa[i] = sa[i - 1] + a[i];
}
if (sa[N] != lowbit(sa[N])) {
printf("no\n");
return 0;
}
f[0][0] = 1;
for (int i = 0; i < N; i ++) {
for (int j = 0; j <= sa[i]; j ++) {
if (!f[i][j]) continue;
int k = sa[i] - j;
if (!j || lowbit(j) >= a[i + 1]) {
int jj = j + a[i + 1], kk = k;
int jh = highbit(jj), kh = highbit(kk);
if (jh != kh) {
// printf("i=%d, j=%d,k=%d,a=%d, jj=%d\n", i, j, k, a[i + 1], jj);
f[i + 1][jj] = 1;
fj[i + 1][jj] = j;
fc[i + 1][jj] = 'l';
} else {
// printf("i=%d, j=%d,k=%d,a=%d, jh=%d,kh=%d\n", i, j, k, a[i + 1], jh, kh);
f[i + 1][jj - jh] = 1;
fj[i + 1][jj - jh] = j;
fc[i + 1][jj - jh] = 'l';
f[i + 1][jj + jh] = 1;
fj[i + 1][jj + jh] = j;
fc[i + 1][jj + jh] = 'l';
}
}
if (!k || lowbit(k) >= a[i + 1]) {
int jj = j, kk = k + a[i + 1];
int jh = highbit(jj), kh = highbit(kk);
if (jh != kh) {
// printf("i=%d, j=%d,k=%d,a=%d, jj=%d\n", i, j, k, a[i + 1], jj);
f[i + 1][jj] = 1;
fj[i + 1][jj] = j;
fc[i + 1][jj] = 'r';
} else {
// printf("i=%d, j=%d,k=%d,a=%d, jh=%d,kh=%d\n", i, j, k, a[i + 1], jh, kh);
f[i + 1][jj - jh] = 1;
fj[i + 1][jj - jh] = j;
fc[i + 1][jj - jh] = 'r';
f[i + 1][jj + jh] = 1;
fj[i + 1][jj + jh] = j;
fc[i + 1][jj + jh] = 'r';
}
}
}
}
// for (int i = 0; i <= N; i ++) {
// for (int j = 0; j <= sa[i]; j ++) {
// printf("%d", (int)f[i][j]);
// if (f[i][j]) printf("(%d%c)", (int)fj[i][j], fc[i][j]);
// }
// printf("\n");
// }
int J = -1;
if (f[N][0]) {
J = 0;
} else if (sa[N] > 1 && f[N][sa[N] / 2]) {
J = sa[N] / 2;
} else if (f[N][sa[N]]) {
J = sa[N];
}
if (J == -1) {
printf("no\n");
return 0;
}
int JJ = J;
for (int i = N; i >= 1;i --) {
if (!f[i][J]) {
printf("gg f[i][J]=0\n");
exit(0);
}
ans[i] = fc[i][J];
J = fj[i][J];
}
assert(strlen(ans + 1) == N);
deque<int> q;
for (int i = 1; i <= N; i ++) {
int t = a[i];
if (ans[i] == 'l') {
for (; q.size() && q.front() == t; q.pop_front()) t *= 2;
q.push_front(t);
} else {
for (; q.size() && q.back() == t; q.pop_back()) t *= 2;
q.push_back(t);
}
}
assert(q.size() == 1);
printf("%s\n", ans + 1);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 30
Accepted
time: 0ms
memory: 2228kb
input:
20 2 8 8 256 2 32 64 64 2 2 64 8 256 128 128 1024 2048 2048 1024 1024
output:
no
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 2412kb
input:
20 1 1 2 4 8 8 8 1024 32 32 16 16 128 1024 1024 128 64 64 4096 512
output:
no
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 2288kb
input:
20 1 2 1 8 4 64 64 4 4 8 2048 32 4096 128 128 64 512 512 256 256
output:
no
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 2512kb
input:
20 1 1 2 2 2 8 16 64 32 128 512 128 128 512 512 1024 1024 2048 1024 1024
output:
lrrllrrlrrlrrllllrrr
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 2244kb
input:
20 2 4 4 4 2 32 128 8 32 32 128 256 256 256 512 8 128 256 2048 4096
output:
no
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 2268kb
input:
20 1 1 2 1 1 1 1 16 32 128 512 8 64 256 1024 1024 2048 2048 512 512
output:
no
result:
ok ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 2328kb
input:
20 4 4 2 2 8 4 4 4 32 256 128 128 256 32 32 512 512 2048 128 4096
output:
no
result:
ok ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 2268kb
input:
20 8 16 16 16 16 16 2 16 512 4 16 2 64 64 2048 128 128 4096 512 512
output:
no
result:
ok ok
Test #9:
score: -30
Wrong Answer
time: 0ms
memory: 2232kb
input:
20 1 1 4 8 2 128 128 16 512 32 64 128 512 512 2048 512 256 256 1024 2048
output:
no
result:
wrong answer participant output is not correct
Subtask #2:
score: 30
Accepted
Test #11:
score: 30
Accepted
time: 0ms
memory: 2388kb
input:
50 1 1 2 2 8 8 8 8 1 1 16 8 8 4 4 8 8 8 64 32 8 8 16 256 256 64 64 128 4 4 256 128 128 256 256 1024 ...
output:
no
result:
ok ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 2260kb
input:
50 1 1 2 2 2 2 4 8 2 2 4 16 4 1 1 2 8 64 64 1 1 128 128 8 1 1 2 4 16 16 8 2 2 4 128 64 64 128 128 20...
output:
no
result:
ok ok
Test #13:
score: 0
Accepted
time: 0ms
memory: 2728kb
input:
50 1 1 1 1 4 2 1 1 2 2 4 4 8 32 32 32 32 32 32 64 128 128 64 64 64 16 16 32 16 8 8 64 32 32 128 16 1...
output:
no
result:
ok ok
Test #14:
score: 0
Accepted
time: 0ms
memory: 2468kb
input:
50 1 1 2 2 1 1 2 1 1 1 1 1 1 8 4 4 4 2 2 4 4 16 256 256 256 256 512 512 256 256 2048 512 32 8 8 16 5...
output:
no
result:
ok ok
Test #15:
score: 0
Accepted
time: 0ms
memory: 2824kb
input:
50 8 4 16 4 16 8 1 1 2 4 16 16 32 32 16 16 64 64 64 16 16 16 16 64 128 128 32 32 64 64 64 256 128 64...
output:
no
result:
ok ok
Test #16:
score: 0
Accepted
time: 0ms
memory: 2328kb
input:
50 1 1 1 1 2 2 1 1 1 1 1 1 2 32 32 1024 8 8 32 8 4 1 1 2 32 16 16 64 32 32 16 8 8 32 32 128 128 64 6...
output:
no
result:
ok ok
Test #17:
score: 0
Accepted
time: 0ms
memory: 2816kb
input:
50 1 1 1 1 1 1 2 16 16 8 8 4 4 8 1 1 2 4 256 16 8 8 16 32 32 32 32 512 512 256 32 32 16 16 32 32 32 ...
output:
lrlllllrrllrrrlllllrrrrrrrrrlllllllllllllllllllllr
result:
ok ok
Test #18:
score: 0
Accepted
time: 0ms
memory: 2260kb
input:
50 1 32 2 1 1 1 1 8 8 4 4 32 32 32 256 32 32 16 16 16 16 512 512 64 64 128 256 512 512 1024 32 1 16 ...
output:
no
result:
ok ok
Test #19:
score: 0
Accepted
time: 0ms
memory: 2748kb
input:
50 1 1 1 1 8 1 1 2 4 2 1 1 128 64 64 128 4 4 1 1 2 2 2 8 2 2 4 8 32 16 8 8 128 128 32 32 32 32 128 5...
output:
no
result:
ok ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 2812kb
input:
50 1 1 1 1 1 1 2 4 2 2 2 2 4 4 1 1 2 16 16 8 2 2 2 2 2 2 1 1 2 4 4 128 8 8 16 64 64 128 1024 1024 51...
output:
lrllllllllrrrrrrrlrlllrrrrrrrlrlrrrrrrllrrrrrrrrrr
result:
ok ok
Subtask #3:
score: 40
Accepted
Test #21:
score: 40
Accepted
time: 17ms
memory: 19332kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 2 1 1 1 1 8 8 16 1 1 1 1 1 1 1 1 16 8 1 1 1 1 1 1 2 8 8 4 4 4 4...
output:
lrllllllllllllllllllllrlrrrrrrrrrllllllllllrrrrrrrrrrrrrrrrrrrrrrrllllllllllllllllllllllllllllllllll...
result:
ok ok
Test #22:
score: 0
Accepted
time: 13ms
memory: 16280kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 4...
output:
lrllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...
result:
ok ok
Test #23:
score: 0
Accepted
time: 8ms
memory: 17300kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1...
output:
lrlllllllllllllllllllllllllllllllllllrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrllrrrrrl...
result:
ok ok
Test #24:
score: 0
Accepted
time: 8ms
memory: 18408kb
input:
1000 1 1 1 1 1 8 4 4 16 8 8 2 2 4 8 4 2 1 1 2 2 4 8 1 1 2 4 2 2 2 1 1 8 1 1 2 4 4 2 2 32 32 4 2 2 8 ...
output:
lrlrllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllrrrrrrrrrrlllllllrrrrrrllllrrrrrrr...
result:
ok ok
Test #25:
score: 0
Accepted
time: 0ms
memory: 15312kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 4 4 1 1 2 1 1 1 1 1 1 2...
output:
lrllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...
result:
ok ok
Test #26:
score: 0
Accepted
time: 4ms
memory: 17120kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 2 2 4 4 4 1 1 1 1 2 2 2 2 1 1 1 1 1 1...
output:
lrllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...
result:
ok ok
Test #27:
score: 0
Accepted
time: 10ms
memory: 19560kb
input:
1000 4 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
no
result:
ok ok
Test #28:
score: 0
Accepted
time: 9ms
memory: 15360kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 2 1 1 1 1 1 1 2 2 4...
output:
lrlllllllllllllllllllllllllllllllllllllllllllllllllrrrrrrrrrrrrrlrrrrrrrrrrrlllrllllllllllllllllllll...
result:
ok ok
Test #29:
score: 0
Accepted
time: 3ms
memory: 15704kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
no
result:
ok ok
Test #30:
score: 0
Accepted
time: 10ms
memory: 17568kb
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 2 2 4 1 1 1 1 1 1 1...
output:
lrllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...
result:
ok ok