UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215374#2777. 2048erican00ms0kbC++113.6kb2024-11-28 21:56:282024-11-28 23:13:38

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[N],top;
pii lst[N];
vector<int> sta[N];


int a[N],pre[N];
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();
}

详细

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

Subtask #1:

score: 0
Memory Limit Exceeded

Test #1:

score: 0
Memory Limit Exceeded

input:

20
2 8 8 256 2 32 64 64 2 2 64 8 256 128 128 1024 2048 2048 1024 1024

output:


result:


Subtask #2:

score: 0
Memory Limit Exceeded

Test #11:

score: 0
Memory Limit Exceeded

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:


result:


Subtask #3:

score: 0
Memory Limit Exceeded

Test #21:

score: 0
Memory 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: