QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#885351#9729. Dividing SequenceBPG_ningWA 451ms29312kbC++202.7kb2025-02-06 15:22:142025-02-06 15:22:34

Judging History

This is the latest submission verdict.

  • [2025-02-06 15:22:34]
  • Judged
  • Verdict: WA
  • Time: 451ms
  • Memory: 29312kb
  • [2025-02-06 15:22:14]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=5e3+10,M=1e5+10,mod=1e9+7,inf=1e9+10;
int n,a[N],vis[N];
LL Base=313,hsh[N],pw[N];
struct node{
    vector<int> a;
    void clear(){a.clear();}
    node(){clear();}
    bool operator < (const node &E) const {
        for(int i=0;i<min(a.size(),E.a.size());i++){
            if(a[i]<E.a[i]) return 1;
            if(a[i]>E.a[i]) return 0;
        }
        return (a.size()<E.a.size());
    }
    node operator + (const node &E) const{
        node B;
        for(int i=0;i<a.size();i++) B.a.push_back(a[i]);
        for(int i=0;i<E.a.size();i++) B.a.push_back(E.a[i]);
        return B;
    }
    void out(){
        cout<<a.size()<<'\n';
        for(int i=0;i<a.size();i++) cout<<a[i]<<' ';
        cout<<'\n';
    }
}f[N];
node range(int l,int r){
    node A;
    for(int i=l;i<=r;i++) A.a.push_back(a[i]);
    return A;
}
void chkmin(node &x,node y){if(y<x) x=y;}
LL get(int l,int r){return (hsh[r]-hsh[l-1]*pw[r-l+1])%mod;}
void read(){
    cin>>n;
    n=5000;
    pw[0]=1;
    for(int i=1;i<=n;i++) pw[i]=pw[i-1]*Base%mod;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]=1;
        hsh[i]=(hsh[i-1]*Base+a[i])%mod;
    }
    a[n+1]=0;
}
void dfs(int x){
    if(vis[x]) return ;
    vis[x]=1;
    int Min=inf,d1=0,d2=0;
    for(int p=x;p<=n;p++) if(a[p]>a[x]) Min=min(Min,a[p]);
    f[x].clear();
    f[x].a.push_back(Min);
    chkmin(f[x],range(x,n));

    for(int l=1;l+x<=n;l++) if(a[x]>=a[x+l]){
        if(x+l*2-1<=n && (get(x,x+l-1)-get(x+l,x+l*2-1))%mod==0){
            if(d1<=3 && x+l*2<=n){
                d1++;
                dfs(x+l*2);
                chkmin(f[x],range(x,x+l-1)+f[x+l*2]);
            }
        }else{
            d2++;
            if(d2<=3){
                int fl=-1,id;
                for(int j=0;j<l;j++){
                    if(a[x+j]<a[x+l+j]){fl=1,id=j; break;}
                    if(a[x+j]>a[x+l+j]){fl=0,id=j; break;}
                }
                if(fl==-1) assert(0);
                if(fl==0) chkmin(f[x],range(x,x+l-1));
                else chkmin(f[x],range(x+l,x+l+id));
            }
        }
        if(a[x]>a[x+l]) break;
    }
}
void work(){
    for(int i=1;i<=n+1;i++) vis[i]=0;
    dfs(1);
    f[1].out();
}
void clear(){
    for(int i=1;i<=n+1;i++){
        f[i].clear();
    }
}
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
//    freopen("nzq.in","r",stdin);
//    freopen("nzq.out","w",stdout);
    int T=1;
    cin>>T;
    while(T--){
        read();
        work();
        clear();
    }
    cerr<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 451ms
memory: 29312kb

input:

5
5
3 1 2 3 2
3
1 1 2
3
3 3 3
5
1 3 1 3 1
5
2 2 1 3 3

output:

2501
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 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 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 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 1 1 1 1...

result:

wrong answer 1st lines differ - expected: '1', found: '2501'