QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#888053#9920. Money Game 2ucup-team5008WA 344ms417436kbC++232.6kb2025-02-07 21:45:592025-02-07 21:46:00

Judging History

This is the latest submission verdict.

  • [2025-02-07 21:46:00]
  • Judged
  • Verdict: WA
  • Time: 344ms
  • Memory: 417436kb
  • [2025-02-07 21:45:59]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define rep2(i,j,k) for(ll i=ll(j);i<ll(k);i++)
#define rep(i,j) rep2(i,0,j)
#define rrep2(i,j,k) for(ll i=ll(j)-1;i>=ll(k);i--)
#define rrep(i,j) rrep2(i,j,0)
#define SZ(a) ll(a.size())
#define eb emplace_back
#define all(a) a.begin(),a.end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const ll inf=LLONG_MAX/4;
template<class T>
bool chmin(T& a,T b){return a>b?a=b,1:0;}
template<class T>
bool chmax(T& a,T b){return a<b?a=b,1:0;}

void print(vl v){for(auto el:v) cout<<el<<" ";cout<<"\n";}

void solve(){
	ll n;cin>>n;
	vl a(n);
	rep(i,n) cin>>a[i];
	if(n<=1000){
		vl ans(n,-inf);
		rep(i,n){
			vl add=a;
			ll now;
			now=i;
			ll carry=0;
			do{
				add[now]+=carry;
				carry+=a[now];
				carry/=2;
				now=(now+1)%n;
			}while(now!=i);
			now=(i+n-1)%n;
			carry=0;
			do{
				add[now]+=carry;
				carry+=a[now];
				carry/=2;
				now=(now+n-1)%n;
			}while(now!=(i+n-1)%n);
			rep(j,n) chmax(ans[j],add[j]);
		}
		print(ans);
		return;
	}
	const ll M=40;
	vvl table(2,vl(n,-inf));
	vvl las(2,vl(n,-inf));
	vvl value(2,vl(n));
	rep(i,2){
		auto mem=a;
		rep(j,n) a.eb(a[j]);
		vvl sum(2*n,vl(M));
		vl last(2*n);
		rep(j,2*n){
			rep(k,M){
				if(j>=k) sum[j][k]=(a[j-k]>>(k+1));
			}
			rep(k,M-1) sum[j][k+1]+=sum[j][k];
			last[j]=j;
			rrep(k,M-1){
				if(sum[j][k+1]!=sum[j][k]){
					last[j]=j-k;
					break;
				}
			}
		}
		vl ok(2*n,-inf);
		rep(j,2*n){
			if(a[j%n]/2%2==0) continue;
			rep2(k,1,M){
				if(j+k>=2*n) break;
				if(a[(j+k)%n]%2==0) break;
				if(j+k>=n&&k) chmax(table[i][(j+k)-n],j-n);
				if(k==M-1) chmax(ok[j+k],j);
			}
		}
		rep2(j,n,2*n){
			value[i][j-n]=sum[j][M-1];
		}
		las[i]=last;
		rep(j,2*n-1) if(a[(j+1)%n]%2) chmax(ok[j+1],ok[j]);
		rep2(j,n,2*n) chmax(table[i][j-n],ok[j]-n);
		rep(j,n) table[i][j]=j-table[i][j]+1;
		rep(j,n) las[i][j]=j-las[i][j]+1;
		a=mem;
		reverse(all(a));
	}
//	reverse(all(table[1]));
//	reverse(all(las[1]));
//	reverse(all(value[1]));
	vl ans(n);
	rep(i,n){
		ll l=(i+n-1)%n;
		ll r=(i+1)%n;
		r=n-1-r;
		ll left=table[0][l];
		ll right=table[1][r];
		ans[i]=a[i]+value[0][l]+value[1][r];
//		cout<<left<<" "<<right<<" "<<las[0][l]<<" "<<las[1][r]<<endl;
		if(left+las[1][r]<=n-1){
			if(left+right<=n-1) ans[i]+=2;
			else ans[i]++;
		}
		else if(right+las[0][l]<=n-1) ans[i]++;
	}
	print(ans);
	return;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	ll t;cin>>t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3712kb

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: 0ms
memory: 3712kb

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: 0
Accepted
time: 0ms
memory: 3712kb

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 18 
9 
10 
7 10 
6 6 5 
3 5 5 3 
18 16 13 15 
9 
4 
18 17 11 14 
9 
0 
7 8 
13 9 11 14 
10 12 
12 7 6 9 
11 11 13 
17 16 17 
12 14 13 12 
10 6 
7 
12 8 9 
5 6 4 4 
6 4 4 
4 
6 5 10 
11 11 13 10 
5 4 4 
8 7 
2 
5 4 6 
11 12 10 
10 7 
13 17 16 12 
9 10 8 6 
6 
6 7 11 7 
9 13 12 11 
14 10 12 1...

result:

ok 2420 numbers

Test #4:

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

input:

1000
2
45733740 736448710
1
384264719
4
658671808 379716865 553196572 534986092
1
668964623
4
711670857 237459905 849354895 187613938
2
394629064 371184128
2
616819808 937720703
1
43217931
3
934395080 888433507 810476236
1
587663687
2
542163302 508453558
4
313836277 584869499 445629251 225398284
4
2...

output:

413958095 759315580 
384264719 
1254322429 1119397578 1175216002 1235849498 
668964623 
1136546502 1064876265 1239809530 1027491789 
580221128 568498660 
1085680159 1246130607 
43217931 
1783849951 1760869165 1721890529 
587663687 
796390081 779535209 
830377481 1020951833 929222211 751348422 
70477...

result:

ok 2440 numbers

Test #5:

score: 0
Accepted
time: 344ms
memory: 417436kb

input:

1
500000
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1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2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

result:

wrong answer 1st numbers differ - expected: '4', found: '3'