QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682643#8057. Best Carry Player 4ShiinaMahiruWA 43ms9804kbC++171.9kb2024-10-27 16:38:432024-10-27 16:38:43

Judging History

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

  • [2024-10-27 16:38:43]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:9804kb
  • [2024-10-27 16:38:43]
  • 提交

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;
    for(int i=0; i<n; ++i)cin >> a[i], a[0] = INF, c[i] = a[i];
    for(int i=0; i<n; ++i)cin >> b[i], b[0] = INF, d[i] = b[i];
    ll res = 0;
    bool f = false;
    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];

    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;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 43ms
memory: 7652kb

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
4
3
3
2
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
1
0
2
4
3
1
5
0
0
2
0
0
1
1
0
0
3
5
3
2
2
2
0
1
2
2
2
0
4
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 5th numbers differ - expected: '3', found: '4'