QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#847245#9920. Money Game 2jakerWA 0ms17908kbC++204.0kb2025-01-07 19:22:272025-01-07 19:22:28

Judging History

This is the latest submission verdict.

  • [2025-01-07 19:22:28]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 17908kb
  • [2025-01-07 19:22:27]
  • Submitted

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
using namespace std;
template<class T> using Arr = std::vector<T>;
typedef long long LL;
const int MAXN = 500002;
const int THRE = 400;
int n;
int a[MAXN*2];
#define REG(x)(((x)-1) % n + 1)
int bit[MAXN*2];
LL val[MAXN*2];
pair<LL,int> left_ans[MAXN*2],right_ans[MAXN*2];
LL ans1[MAXN*2],ans2[MAXN*2];

void BruteF() {
    static LL f[THRE+10][2*THRE+10];
    static LL g[THRE+10][2*THRE+10];
    for(int i = 1;i <= n;++i)
        for(int j = 1;j <= 2*n;++j)
            g[i][j] = f[i][j] = 0;
    for(int i = 1;i <= n;++i) {
        f[i][i] = 0;
        for(int j = i+1; j <= i+n-1;++j)
            f[i][j] = ( f[i][j-1] + a[REG(j-1)] ) / 2;
        g[i][n+i] = 0;
        for(int j = n+i-1; j > i; --j)
            g[i][j] = ( g[i][j+1] + a[REG(j+1)] ) / 2;
    }
    for(int i = 1;i <= n;++i) {
        LL ans = 0;
        for(int j = 1; j <= n; ++j)
            ans = std::max( ans , f[j%n+1][i] + f[j%n+1][n+i] + g[j][i] + g[j][n+i] );
        ans1[i] = ans + a[i];
        cout << ans1[i] << " ";
    }
    cout << endl;
}

void solve() {
    cin >> n;
    for(int i = 1;i <= n;++i)  {
        cin >> a[i];
        a[i+n] = a[i];
    }

    if( n < THRE ) BruteF() , cerr << endl << endl;
    
    LL nxt;
    for(int i = 1;i <= 2*n;++i) {
        int p = i;
        LL now = a[p];
        for(; p >= 1 && now; --p) {
            if( i - p == n ) break;
            if( now > 0 && p != i )
                right_ans[p] = make_pair( val[p+1] , i );
            // if( i == 2 ) {
            //     cerr << "p = " << p << ", now = " << now << endl;
            // }
            val[p] += (now + bit[p])/2;
            nxt = (now+bit[p])/2;
            if( now&1 && bit[p] ) bit[p] = 0;
            else if( !bit[p] && now&1 ) bit[p] = 1;
            now = nxt;
        }
        // if( i <= 20 ) {
        //     // cerr << "i = " << i << ", p = "<< p << ", ans[p] = " << right_ans[p].first << endl; 
        //     rep(ttt,0,5) cerr << val[ttt] << " "; cerr << endl;
        //     rep(ttt,0,5) cerr << bit[ttt] << " "; cerr << endl;
        //     cerr << right_ans[1].first << endl << endl;
        // }
    }
    for(int i = 1;i <= 2*n;++i) val[i] = bit[i] = 0;
    for(int i = 2*n;i >= 1;--i) {
        int p = i;
        LL now = a[p];
        for(; p <= 2*n && now;++p) {
            if( p - i == n ) break;
            if( now > 0 && p != i )
                left_ans[p] = make_pair( val[p-1] , i );
            val[p] += ( now + bit[p] ) / 2;
            nxt = ( now + bit[p] ) / 2;
            if( now&1 && bit[p] ) bit[p] = 0;
            else if( !bit[p] && now&1 ) bit[p] = 1;
            now = nxt;
        }
    }

    for(int i = 1;i <= n;++i) {
        LL ans = right_ans[i].first + left_ans[i+n].first + a[i];
        // if( i <= 20 ) {
        //     cerr << left_ans[i+n].first << " " << right_ans[i].first << endl;
        // }
        int pos1 = right_ans[i].second,
            pos2 = left_ans[i+n].second;

        // if( i == 200 ) {
        //     cerr << left_ans[i+n].first << " " << left_ans[i+n].second << endl;
        //     cerr << right_ans[i].first << " " << right_ans[i].second << endl;
        // }

        if( pos1 > n ) pos1 -= n;
        if( pos2 > n ) pos2 -= n;
        // if( i == 50 ) cerr << endl << "****" << pos1 << " " << pos2 << endl;
        if( pos1 > i && pos2 < i );
        else if( pos1 > i ) {
            if( pos1 < pos2 );
            else
                if( right_ans[i].first + left_ans[i+n].first > 0 ) 
                    --ans;
        }
        else {
            if( pos1 < pos2 );
            else 
                if( right_ans[i].first + left_ans[i+n].first > 0 ) 
                    --ans;
        }
        cout << ans << " ";
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--)
        solve();
    return 0 ;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 17908kb

input:

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

output:

6 5 7 8 8 
6 5 7 8 8 
4 4 5 4 4 
5 6 7 7 7 
1000000000 
1000000002 

result:

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