QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#682741#8057. Best Carry Player 4ShiinaMahiruWA 40ms9784kbC++172.4kb2024-10-27 17:10:592024-10-27 17:11:00

Judging History

你现在查看的是最新测评结果

  • [2024-10-27 17:11:00]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:9784kb
  • [2024-10-27 17:10:59]
  • 提交

answer

// #pragma GCC optimize(2)
#include<bits/stdc++.h>
#define endl '\n'
#define lowbits(x) ((x)&((-x)))
#define INF 0x3f3f3f3f
#define uu __int128
#define PI acos(-1)
#define ls k<<1
#define rs k<<1|1
using namespace std;
typedef  long long ll;
typedef  unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PII;
constexpr int N=5e5+10, M=2*N;
constexpr int mod=998244353;
constexpr double eps=1e-9;
int nx[] = {0, 0, 1, -1}, ny[] = {1, -1, 0, 0};


int n;
int a[N], b[N];
int c[N], d[N];
void solve(){
    cin >> n;
    ll sz = 0, sz2 = 0;
    for(int i=0; i<n; ++i)cin >> a[i], c[i] = a[i], sz += a[i];
    for(int i=0; i<n; ++i)cin >> b[i], d[i] = b[i], sz2 += b[i];
    if(sz > sz2){
        b[0] += sz - sz2;
    }
    else a[0] += sz2 - sz;
    c[0] = a[0];d[0] = b[0];
    ll res = 0;
    bool f = false;
    // for(int i=0; i<n; ++i){
    //     if(a[i] && b[n-i]){
    //         f = true;
    //         ++res;
    //         --a[i], --b[n-i];
    //         break;
    //     }
    // }
    
    for(int i=n-1, j=0; i>=0; --i){
        if(!a[i])continue;
        while(j < n && (!b[j] || i+j<n-1))++j;
        if(j==n)break;
        if(i+j >= n)f = true;
        int d = min(a[i], b[j]);
        a[i] -= d;
        b[j] -= d;
        res += d;
        if(a[i])++i;
    }
    if(a[n-1])res += a[n-1];
    if(b[n-1])res += b[n-1];
    // for(int i=0; i<n; ++i)cout << a[i] << " \n"[i == n-1];
    // for(int i=0; i<n; ++i)cout << b[i] << " \n"[i == n-1];
    // cout << res << ' ' << f << endl;
    if(f){
        cout << res << endl;return;
    }
    ll ans = 0;
    for(int i=0; i<n; ++i)a[i] = c[i], b[i] = d[i];
    int t = 0;
    for(int i=n-1, j=0; i>=0; --i){
        if(!a[i])continue;
        while(j < n && (!b[j] || i+j+t<n))++j;
        if(j==n)break;
        if(t == 0){
            t = 1;
            a[i]--;
            b[j]--;
            j = 0, i = n;
            ++ans;
            continue;
        }
        int d = min(a[i], b[j]);
        a[i] -= d;
        b[j] -= d;
        ans += d;
        if(a[i])++i;
    }
    if(a[n-1] + t >= n)ans += a[n-1];
    if(b[n-1] + t >= n)ans += b[n-1];

    cout << ans << endl;


}


signed main()
{   
    ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
    int t = 1;
    // cout << fixed << setprecision(9)
    cin >> t;
    while(t--)solve();
    return 0;

}

详细

Test #1:

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

input:

5
2
1 2
3 4
3
1 0 1
0 1 0
4
1 0 0 1
1 1 1 1
5
123456 114514 1919810 233333 234567
20050815 998244353 0 0 0
10
5 3 5 3 2 4 2 4 1 5
9 9 8 2 4 4 3 5 3 0

output:

5
1
2
467900
29

result:

ok 5 number(s): "5 1 2 467900 29"

Test #2:

score: -100
Wrong Answer
time: 40ms
memory: 9784kb

input:

100000
5
0 1 1 1 1
0 0 1 0 0
5
0 0 0 0 0
1 1 1 0 0
5
0 0 2 1 1
0 2 1 0 1
5
0 0 0 0 0
1 2 1 0 0
5
0 1 0 1 1
0 0 1 1 1
5
2 0 0 0 1
1 0 0 0 3
5
2 0 0 1 1
0 2 1 1 1
5
0 0 0 0 2
0 0 0 0 1
5
0 0 0 0 0
0 1 1 0 0
5
4 0 0 0 0
0 0 0 1 0
5
0 0 0 0 1
2 1 1 0 0
5
0 2 3 0 0
0 0 0 1 0
5
1 1 1 0 1
1 0 1 0 1
5
0 0 0...

output:

2
0
4
0
3
3
3
2
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
1
0
2
3
3
1
5
0
0
2
0
0
1
1
0
0
3
5
3
2
2
2
0
1
2
2
2
0
3
0
2
1
1
0
1
0
4
0
0
2
2
0
3
3
0
2
0
1
0
0
1
1
2
0
3
4
0
2
5
0
2
1
0
0
0
3
2
3
0
2
0
4
3
3
0
2
2
0
1
3
1
1
0
0
0
1
0
3
2
2
0
2
1
1
0
1
0
0
2
4
1
3
3
2
2
2
0
2
0
0
2
3
1
3
1
0
2
2
3
0
1
2
0
1
1
...

result:

wrong answer 51510th numbers differ - expected: '0', found: '5'