QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#847358#9920. Money Game 2eastcloudWA 2ms3832kbC++232.6kb2025-01-07 21:05:062025-01-07 21:05:14

Judging History

This is the latest submission verdict.

  • [2025-01-07 21:05:14]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3832kb
  • [2025-01-07 21:05:06]
  • Submitted

answer


#include<bits/stdc++.h>

#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define eb emplace_back
#define IL inline
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define Fol(i,k,j) for(int i=(k);i>=(j);i--)

using namespace std;

#define N 500005

int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
void write(int x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}

void debug(auto &&...x){
    ((cerr<<x<<' '),...);
    cerr<<'\n';
}

deque<pi> f,g;
vector<pi> L[N],R[N];
int a[N],n;

void init(int opt){
    f.push_back(mp(n,a[n]));
    Fol(i,n-1,1){
        g.push_back(mp(i,a[i]));
        for(auto [id,val]:f){
            if(val/2+a[i]!=g.back().se)g.push_back(mp(id,val/2+a[i]));
        }
        swap(f,g);
        while(g.size())g.pop_back();
    }
    if(opt)for(auto _:f)L[1].pb(_);
    else for(auto _:f)R[n].eb(n-_.fi+1,_.se);
    Fol(i,n,2){
        if(f.back().fi==i)f.pop_back();
        g.push_back(mp(i,a[i]));
        for(auto [id,val]:f){
            if(val/2+a[i]!=g.back().se)g.push_back(mp(id,val/2+a[i]));
        }
        swap(f,g);
        for(auto _:f){
            if(opt)L[i].pb(_);
            else R[n-i+1].eb(n-_.fi+1,_.se);
        }
        while(g.size())g.pop_back();
    }
}

void solve(){
    n=read();
    For(i,1,n)a[i]=read(),L[i].clear(),R[i].clear();init(1);
    reverse(a+1,a+n+1);init(0);reverse(a+1,a+n+1);
    auto dis1=[&](int x,int y){
        if(x<=y)return y-x;
        else return y+n-x;
    };
    auto dis2=[&](int x,int y){
        if(y<=x)return x-y;
        else return x+n-y;
    };
    For(i,1,n){
        int pos=R[i].size()-1,res=0;
        for(auto [id,val]:L[i]){
            
            while(pos>=0 && dis1(i,id)+dis2(i,R[i][pos].fi)>=n)pos--;
            if(pos>=0)res=max(res,val+R[i][pos].se-a[i]);
            res=max(res,val);
        }
        for(auto [id,val]:R[i]){
            //debug(i,id,val,dis1(i,id));
            res=max(res,val);
        }
        write(res);putchar(' ');
    }
    putchar('\n');
}

int main(){
    #ifdef EAST_CLOUD
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    #endif

    int T=read();while(T--)solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3832kb

input:

3
5
2 1 4 3 5
5
2 1 3 1 2
1
1000000000

output:

6 5 7 8 8 
4 4 5 4 4 
1000000000 

result:

ok 11 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 3528kb

input:

1
10
8 15 18 15 13 4 14 4 17 5

output:

30 37 41 39 34 27 29 26 31 27 

result:

ok 10 numbers

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3580kb

input:

1000
4
8 9 7 9
1
9
1
10
2
3 9
3
4 3 2
4
0 4 3 1
4
10 8 4 6
1
9
1
4
4
10 10 1 6
1
9
1
0
2
4 6
4
8 1 6 7
2
5 10
4
9 2 1 4
3
5 5 9
3
9 8 9
4
4 8 5 6
2
10 1
1
7
3
9 2 4
4
2 4 1 2
3
5 2 1
1
4
3
2 0 9
4
7 3 10 1
3
4 1 2
2
6 4
1
2
3
3 1 5
3
5 8 4
2
9 3
4
5 9 10 3
4
6 5 4 0
1
6
4
3 1 10 1
4
1 9 5 7
4
8 1 6 ...

output:

18 18 17 21 
14 
14 
12 20 
9 6 9 
5 5 5 5 
18 16 13 18 
11 
11 
20 21 11 17 
9 
9 
9 13 
14 9 11 16 
15 20 
13 7 6 9 
14 16 18 
23 23 19 
17 17 16 16 
15 11 
12 
16 10 10 
6 6 4 6 
6 4 4 
4 
9 5 10 
11 11 13 11 
8 4 5 
9 10 
9 
7 4 7 
11 15 12 
15 13 
14 20 19 15 
11 10 8 7 
8 
7 7 11 8 
11 17 14 1...

result:

wrong answer 4th numbers differ - expected: '18', found: '21'