QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#712031 | #8057. Best Carry Player 4 | acwing_gza# | Compile Error | / | / | C++20 | 3.5kb | 2024-11-05 14:20:53 | 2024-11-05 14:20:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef ll i64;
typedef __int128 i128;
constexpr int maxn=5e5+9;
int m;
i64 a[maxn],b[maxn];
i64 ta[maxn],tb[maxn];
ll suma,sumb;
void solve()
{
cin>>m;
int n=m; suma=sumb=0;
for(int i=0;i<m;++i) cin>>a[i],suma+=ta[i]=a[i];
for(int i=0;i<m;++i) cin>>b[i],sumb+=tb[i]=b[i];
int maxa=0,maxb=0;
// printf("suma=%lld sumb=%lld\n",suma,sumb);
if(suma>sumb)
{
for(int i=0;i<m;++i) swap(a[i],b[i]);
swap(suma,sumb);
}
a[0]+=sumb-suma;
for(int i=m-1;i>=0;--i)
if(a[i])
{
maxa=i;
break;
}
for(int i=m-1;i>=0;--i)
if(b[i])
{
maxb=i;
break;
}
int ptr=m-1;
ll ans=0;
int flag=0,flag2=0;
ll ss=0;
for(int i=0;i<m;++i)
{
ss+=b[m-i];
if(ss && a[i]) { flag2=1; break; }
}
for(int i=0;i<m;++i)
{
if(!a[i]) continue;
while(ptr>=0 && !b[ptr]) --ptr;
if(ptr<0) break;
if(i+ptr>=m) flag=1;
while(ptr>=m-1-i && a[i])
{
int match=std::min(a[i],b[ptr]);
//printf("match %d of %d in a and %d in b\n",match,i,ptr);
ans+=match;
b[ptr]-=match;
a[i]-=match;
if(!b[ptr]) --ptr;
}
if(ptr<0) break;
}
for(int i=m-maxb;i<m;++i)
if(a[i]) flag=1;
for(int i=m-maxa;i<m;++i)
if(b[i]) flag=1;
cout<<(flag?ans:(flag2==0?0:ans-1))<<endl;
}
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
typedef long long ll;
typedef ll i64;
typedef __int128 i128;
constexpr int maxn=5e5+9;
int m;
i64 a[maxn],b[maxn];
i64 ta[maxn],tb[maxn];
ll suma,sumb;
void solve()
{
cin>>m;
int n=m; suma=sumb=0;
for(int i=0;i<m;++i) cin>>a[i],suma+=ta[i]=a[i];
for(int i=0;i<m;++i) cin>>b[i],sumb+=tb[i]=b[i];
int maxa=0,maxb=0;
// printf("suma=%lld sumb=%lld\n",suma,sumb);
if(suma>sumb)
{
for(int i=0;i<m;++i) swap(a[i],b[i]);
swap(suma,sumb);
}
a[0]+=sumb-suma;
for(int i=m-1;i>=0;--i)
if(a[i])
{
maxa=i;
break;
}
for(int i=m-1;i>=0;--i)
if(b[i])
{
maxb=i;
break;
}
int ptr=m-1;
ll ans=0;
int flag=0,flag2=0;
ll ss=0;
for(int i=0;i<m;++i)
{
ss+=b[m-i];
if(ss && a[i]) { flag2=1; break; }
}
for(int i=0;i<m;++i)
{
if(!a[i]) continue;
while(ptr>=0 && !b[ptr]) --ptr;
if(ptr<0) break;
if(i+ptr>=m) flag=1;
while(ptr>=m-1-i && a[i])
{
int match=std::min(a[i],b[ptr]);
//printf("match %d of %d in a and %d in b\n",match,i,ptr);
ans+=match;
b[ptr]-=match;
a[i]-=match;
if(!b[ptr]) --ptr;
}
if(ptr<0) break;
}
for(int i=m-maxb;i<m;++i)
if(a[i]) flag=1;
for(int i=m-maxa;i<m;++i)
if(b[i]) flag=1;
cout<<(flag?ans:(flag2==0?0:ans-1))<<endl;
}
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
详细
answer.code:2:21: error: stray ‘#’ in program 2 | using namespace std;#include <bits/stdc++.h> | ^ answer.code:2:31: error: ‘bits’ was not declared in this scope 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ answer.code:2:36: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ | std answer.code:2:31: error: ‘bits’ was not declared in this scope 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ answer.code:2:36: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ | std answer.code:2:31: error: ‘bits’ was not declared in this scope 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ answer.code:2:36: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ | std answer.code:2:31: error: ‘bits’ was not declared in this scope 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ answer.code:2:36: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ | std answer.code:2:31: error: ‘bits’ was not declared in this scope 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ answer.code:2:36: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ | std answer.code:2:31: error: ‘bits’ was not declared in this scope 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ answer.code:2:36: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ | std answer.code:2:31: error: ‘bits’ was not declared in this scope 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ answer.code:2:36: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ | std answer.code:2:31: error: ‘bits’ was not declared in this scope 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ answer.code:2:36: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ | std answer.code:2:31: error: ‘bits’ was not declared in this scope 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ answer.code:2:36: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 2 | using namespace std;#include <bits/stdc++.h> | ^~~~ | std answer.code:2:22: error: ‘include’ does not name a type 2 | using namespace std;#include <bits/stdc++.h> | ^~~~~~~ answer.code:83:15: error: redefinition of ‘constexpr const int maxn’ 83 | constexpr int maxn=5e5+9; | ^~~~ answer.code:7:15: note: ‘constexpr const int maxn’ previously defined here 7 | constexpr int maxn=5e5+9; | ^~~~ answer.code:84:5: error: redefinition of ‘int m’ 84 | int m; | ^ answer.code:8:5: note: ‘int m’ previously declared here 8 | int m; | ^ answer.code:85:5: error: redefinition of ‘i64 a [500009]’ 85 | i64 a[maxn],b[maxn]; | ^ answer.code:9:5: note: ‘i64 a [500009]’ previously declared here 9 | i64 a[maxn],b[maxn]; | ^ answer.code:85:13: error: redefinition of ‘i64 b [500009]’ 85 | i64 a[maxn],b[maxn]; | ^ answer.code:9:13: note: ‘i64 b [500009]’ previously declared here 9 | i64 a[maxn],b[maxn]; | ^ answer.code:86:5: error: redefinition of ‘i64 ta [500009]’ 86 | i64 ta[maxn],tb[maxn]; | ^~ answer.code:10:5: note: ‘i64 ta [500009]’ previously declared here 10 | i64 ta[maxn],tb[maxn]; | ^~ answer.code:86:14: error: redefinition of ‘i64 tb [500009]’ 86 | i64 ta[maxn],tb[maxn]; | ^~ answer.c...