QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#771473 | #8057. Best Carry Player 4 | Tomorrow# | WA | 75ms | 3852kb | C++17 | 1.9kb | 2024-11-22 13:19:18 | 2024-11-22 13:19:22 |
Judging History
answer
#include <bits/extc++.h>
using namespace std;
#define C const
#define CE constexpr
#define TL template
#define TN typename
#define OP operator
#define pb push_back
#define ft first
#define sd second
#define mi (l+(r-l)/2)
#define TTT TL<TN T>
#define BE(v) v.begin(), v.end()
#define U unsigned
#define VD void
#define I int
#define LL long long
#define D double
using STR = string;
using PII = pair<I, I>;
TTT using V = vector<T>;
#define FORX(v) for(auto& x:v)
#define FOR(i,b,e) for(I i = b, _e = e;i<_e;++i)
#define FORR(i,b,e) for(I i = b, _e = e;i>_e;--i)
#define FUNC(T,f,...) function<T(__VA_ARGS__)> f = [&](__VA_ARGS__)->T
TTT VD setmin(T& a, C T& b){if(b<a)a=b;}
TTT VD setmax(T& a, C T& b){if(a<b)a=b;}
VD test()
{
I m; cin>>m;
V<I> a(m), b(m);
LL sa = 0, sb = 0;
FORX(a)cin>>x, sa += x;
FORX(b)cin>>x, sb += x;
if(sa<sb)a[0]+=sb-sa;
if(sa>sb)b[0]+=sa-sb;
I l = 0, r = m-1;
LL cnt[2] = {0,0};
I mxl = -1e9, mxr = -1e9;
while(l<m&&r>=0)
{
I num = min(a[l], b[r]);
if(num)setmax(mxr,r), setmax(mxl,l);
a[l]-=num; b[r]-=num;
cnt[l+r>=m]+=num;
if(a[l]==0)++l;
else if(b[r]==0)
{
--r;
if(l+r<m-1)++l;
}
}
if(cnt[1])
{
cout<<cnt[0]+cnt[1]<<'\n';
}
else
{
I mxa = -1e9, mxb = -1e9;
FOR(i,0,m)if(a[i]>0)setmax(mxa, i);
FOR(i,0,m)if(b[i]>0)setmax(mxb, i);
if(mxa+mxr>=m||mxb+mxl>=m)cout<<cnt[0]<<'\n';
else if(mxl+mxr>=m)cout<<cnt[0] - 1<<'\n';
else cout<<"0\n";
}
}
I main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen("test.in","r"))
{
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
}
I t = 1;
cin >> t;
while(t--)test();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 0
Accepted
time: 42ms
memory: 3628kb
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:
ok 100000 numbers
Test #3:
score: 0
Accepted
time: 28ms
memory: 3852kb
input:
1000 500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
0 1 1 2 2 2 0 0 0 3 1 1 2 0 1 0 1 1 3 0 0 4 3 1 4 4 0 0 2 1 3 3 0 0 1 0 1 1 0 0 2 1 2 0 3 1 3 1 3 4 2 1 1 2 3 0 0 1 2 0 0 1 1 1 1 2 1 2 2 0 2 2 1 1 3 0 0 1 2 0 1 3 0 0 1 1 0 0 1 0 3 1 2 0 0 5 1 1 1 3 1 4 1 0 0 0 0 0 1 3 1 2 1 0 0 0 0 0 1 1 0 4 0 1 1 3 0 1 0 0 2 3 0 1 2 1 1 1 0 3 0 0 3 2 1 1 0 1 0 1 ...
result:
ok 1000 numbers
Test #4:
score: -100
Wrong Answer
time: 75ms
memory: 3632kb
input:
100000 5 119777838 337555280 806504015 458289944 321614229 979242871 431783189 423329635 193632121 7339369 5 189264782 667669243 753322761 861814678 224007583 977519325 104432095 940220826 712094722 903574615 5 977791540 278658984 601762324 633391706 36807634 689562032 997406456 118939957 891425821 ...
output:
1377698543 2884329841 1699584169 2132012702 2531472710 2754014935 2585135038 2577893498 2034726862 2303377730 1476887044 2618960687 1626312268 1068946376 600795101 927483202 2151016849 2256729729 2291627593 1751199962 2412405837 1884010446 2553701265 2014856631 848686688 1069641213 2412585811 167144...
result:
wrong answer 39th numbers differ - expected: '1572566306', found: '-1412970174'