QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#654141#8057. Best Carry Player 4zqx#WA 41ms7952kbC++231.4kb2024-10-18 21:09:042024-10-18 21:09:06

Judging History

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

  • [2024-10-18 21:09:06]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:7952kb
  • [2024-10-18 21:09:04]
  • 提交

answer

#include<bits/stdc++.h>
#define AC return 0;
#define int long long 
#define pii pair<int,int>
#define all(tar) tar.begin(),tar.end()
const int N=1e6+5;
const int mod=998244353; 
using namespace std;
int n,m,t,d;
int a[N];
int b[N];
bool use[N];
bool vis[N];
void solve(){
   cin>>n;  
   set<int>st;
   for(int i=0;i<n;i++){
      cin>>a[i];
      use[i]=0;
   }
   a[n]=0;
   b[n]=0;
   for(int i=0;i<n;i++){
      cin>>b[i];
      if(b[i])st.insert(i);
   }
   a[0]=b[0]=1e18;
   int pos=0,maxn=1e9;
   for(int i=1;i<n;i++){
    if(!a[i])continue;
    auto it=st.lower_bound(n-i);
    if(it==st.end())continue;
    int x=*it;
    if(x+i<maxn){
        maxn=x+i;
        pos=i;
    }
   }
   if(pos){
    int ans=0; 
    bool flag=0;
     for(int l=0,r=n-1;l<=n-1;){
        while(l+r<n-1&&l<=n-1)++l;
        ans+=min(a[l],b[r]);
        int x=min(a[l],b[r]);
        a[l]-=x;
        b[r]-=x;
        if(x)use[l]=1,vis[r]=1;
        if(l+r>=n&&x)flag=1;
        while(a[l]==0&&l<=n-1)++l;
        while(r>=1&&b[r]==0)--r;
     }
     for(int i=1;i<n;i++){
        if(use[i-1]&&a[i])flag=1;
        if(vis[i]&&b[i])flag=1;
        use[i]|=use[i-1];
        vis[i]|=vis[i-1];
     }
     if(!flag)ans--; 
     cout<<ans<<'\n';
   }
   else cout<<"0\n";
}
signed main(){
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int T;cin>>T;
    while(T--) solve();
   
   AC
}   

詳細信息

Test #1:

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

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: 41ms
memory: 7696kb

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
3
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
2
0
0
2
4
1
3
3
2
2
2
0
2
0
0
2
3
1
3
1
0
3
2
3
0
1
2
0
1
1
...

result:

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