ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215369 | #2777. 2048 | nodgd | 0 | 21ms | 2200kb | C++11 | 2.7kb | 2024-11-28 21:36:13 | 2024-11-28 23:13:02 |
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, A;
int a[MAX_N];
bitset<MAX_A> f[MAX_N];
char ans[MAX_N];
int lowbit(int x) {
return x & -x;
}
int highbit(int x) {
return x ? 31 - __builtin_clz(x) : -1;
}
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i ++) {
scanf("%d", &a[i]);
A += a[i];
}
if (A & A - 1) {
printf("no\n");
return 0;
}
A = 0;
f[0][0] = 1;
for (int i = 1; i <= N; i ++) {
A += a[i];
for (int j = 0; j <= A; j ++) {
if (highbit(j) == highbit(A - j)) continue;
int t = 0;
if (j >= a[i] && lowbit(j) >= a[i]) {
t |= f[i - 1][j - a[i]];
}
if (A - j >= a[i] && lowbit(A - j) >= a[i]) {
t |= f[i - 1][j];
}
f[i][j] = t;
}
}
int J = -1;
if (f[N][0]) J = 0;
else if (A > 1 && f[N][A / 2]) J = A / 2;
int JJ = J;
if (J == -1) {
printf("no\n");
return 0;
}
for (int i = N; i >= 1; A -= a[i], i --) {
if (!f[i][J]) {
printf("gg f[i][J]=0\n");
exit(0);
}
if (J >= a[i] && lowbit(J) >= a[i] && f[i - 1][J - a[i]]) {
ans[i] = 'l', J -= a[i];
} else if (A - J >= a[i] && lowbit(A - J) >= a[i] && f[i - 1][J]) {
ans[i] = 'r';
} else {
printf("gg\n");
exit(0);
}
}
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);
}
}
if (q.size() != 1) {
A = 0;
for (int i = 1; i <= N; i ++) A += a[i];
printf("A=%d, JJ=%d, qs=%d\n", A, JJ, (int)q.size());
}
printf("%s\n", ans + 1);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 30
Accepted
time: 0ms
memory: 2196kb
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: 2200kb
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: 2196kb
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: -30
Wrong Answer
time: 0ms
memory: 2200kb
input:
20 1 1 2 2 2 8 16 64 32 128 512 128 128 512 512 1024 1024 2048 1024 1024
output:
no
result:
wrong answer participant output is not correct
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 30
Accepted
time: 0ms
memory: 2200kb
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: 2196kb
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: 2196kb
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: 2ms
memory: 2196kb
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: 2ms
memory: 2196kb
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: 2200kb
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: -30
Wrong Answer
time: 1ms
memory: 2200kb
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:
no
result:
wrong answer participant output is not correct
Subtask #3:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 16ms
memory: 2196kb
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:
no
result:
wrong answer participant output is not correct