UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215378#2777. 2048erican0201ms79500kbC++113.6kb2024-11-28 21:57:302024-11-28 23:13:47

answer

/*  Erica N  */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define endl '\n'
#define mp make_pair
// #define int long long
#define ull unsigned long long
#define pii pair<int, int>
#define ps second
#define pf first
#define itn int
#define rd read()
int read(){
    int xx = 0, ff = 1;char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-')ff = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
    return xx * ff;
}
// void write(int out) {
// 	if (out < 0)
// 		putchar('-'), out = -out;
// 	if (out > 9)
// 		write(out / 10);
// 	putchar(out % 10 + '0');
// }
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() { cerr << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (int v: a) cerr << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }


const int N = 9e6 + 5;
const int INF = 1e18;
const int M = 1e7;
const int MOD = 1e9 + 7;

int ans[1005],top;
pii lst[N];
vector<int> sta[1005];


int a[1005],pre[1005];
bitset<N> f;
int _id[N];
unordered_map<int,int> id;

inline int lowbit(int x){
    return x&-x;
}
inline bool check(int a){
    int x=a;
    int res=0;
    while(a){
        res+=a&1;
        a>>=1;
    }

    if(res==1)return 1;
    if(res>2)return 0;
    return lowbit(x)==lowbit(x>>14);
}

inline int process(int a,int x,int op){
    if(op){
        if(lowbit(a)<lowbit(x)&&a)return 0;
        a+=x;
        return a;
    }else{
        if(lowbit(a>>14)<lowbit(x)&&(a>>14))return 0;
        a+=x<<14;
        return a;
    }
    return 0;
}

void init(int x){
    for(int i=0;i<=x;i++){
        f[i]=0;
    }
}

void solve() {
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);

    id.clear();

    int n=rd;
    for(int i=1;i<=n;i++){
        a[i]=rd;
        pre[i]=pre[i-1]+a[i];
        while(sta[i].size())sta[i].pop_back();
    }

    int idx=0;

    for(int i=0;i<=(1<<13);i++){
        for(int j=0;j<=n;j++){
            if(i>pre[j])continue;
            id[i<<14|(pre[j]-i)]=++idx;
            _id[idx]=i<<14|(pre[j]-i);
            sta[j].pb(idx);
            // cdbg(j,idx);
        }
    }

    if(idx>=N)assert(0);


    // f.reset();

    f[1]=1;
    for(int i=1;i<=n;i++){
        for(int s:sta[i-1]){
            if(f[s]){
                int nxt=process(_id[s],a[i],0);
                if(nxt){
                    nxt=id[nxt];
                // cdbg("L",i,s,nxt,_id[s],a[i],process(_id[s],a[i],0));
                    if(nxt==s)assert(0);
                    f[nxt]=1;
                    lst[nxt]={s,0};

                }
                nxt=process(_id[s],a[i],1);
                if(nxt){
                    nxt=id[nxt];
                // cdbg("R",i,s,nxt,_id[s],a[i],process(_id[s],a[i],1));
                    if(nxt==s)assert(0);

                    f[nxt]=1;
                    lst[nxt]={s,1};

                }
            }
        }
    }


    for(int s:sta[n]){
        // if(f[s])cdbg(s);
        if(f[s]&&check(_id[s])==1){
            while(s){
                ans[++top]=lst[s].ps;
                s=lst[s].pf;
            }

            while(n){
                if(ans[n--])putchar('r');
                else putchar('l');
            }
            puts("");
            init(idx);
            return ;
        }
    }

    puts("no");

    init(idx);

}

signed main(){
    solve();
}

Details

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

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 30
Accepted
time: 8ms
memory: 73392kb

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: 11ms
memory: 73488kb

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: 12ms
memory: 74276kb

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: 12ms
memory: 73392kb

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: 20ms
memory: 75372kb

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: 19ms
memory: 75532kb

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: 20ms
memory: 76024kb

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: 35ms
memory: 79500kb

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: 22ms
memory: 76036kb

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: 31ms
memory: 76356kb

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: 11ms
memory: 75384kb

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
Time Limit Exceeded

Test #21:

score: 0
Time Limit Exceeded

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:


result: