UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215338#2777. 2048nodgd016ms2196kbC++111.9kb2024-11-28 19:26:022024-11-28 23:10:53

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 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];
        // printf("f[%d]=", i);
        for (int j = 0; j <= A; j ++) {
            int t = 0;
            if ((j & -j) >= a[i]) {
                t |= f[i - 1][j - a[i]];
            }
            if ((A - j & j - A) >= a[i]) {
                t |= f[i - 1][j];
            }
            f[i][j] = t;
            // printf("%d", t);
        }
        // printf("\n");
    }
    if (f[N].none()) {
        printf("no\n");
        return 0;
    }
    int J = -1;
    for (int j = 0; j <= A; j += A / 2) {
        if (f[N][j]) {
            J = j;
            break;
        }
    }
    for (int i = N; i >= 1; A -= a[i], i --) {
        // printf("i=%d, J=%d\n", i, J);
        if ((J & -J) >= a[i] && f[i - 1][J - a[i]]) {
            ans[i] = 'l', J -= a[i];
        } else {
            ans[i] = 'r';
        }
    }
    printf("%s\n", ans + 1);
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 30
Accepted
time: 0ms
memory: 2192kb

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: 2196kb

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: 2192kb

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: 2192kb

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
Runtime Error

Test #11:

score: 30
Accepted
time: 0ms
memory: 2192kb

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: 1ms
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: 1ms
memory: 2192kb

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: -30
Runtime Error

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:


result:


Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 14ms
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