QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637167 | #8057. Best Carry Player 4 | ucup-team073# | WA | 5ms | 5708kb | C++20 | 2.8kb | 2024-10-13 10:33:12 | 2024-10-13 10:33:12 |
Judging History
answer
#include<bits/stdc++.h>
#ifdef LOCAL
#define debug(...) printf(__VA_ARGS__)
#define edebug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define edebug(...)
#endif
#define int ll
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define nrep(i, x, y) for(int i = x; i >= y; --i)
#define ll long long
#define pii std::pair<int,int>
#define pb emplace_back
#define fi first
#define se second
template <class T>
inline void ckmax(T &a, T b) {
if(a < b) a = b;
}
template <class T>
inline void ckmin(T &a, T b) {
if(a > b) a = b;
}
auto rt_YES = []{puts("YES");};
auto rt_Yes = []{puts("Yes");};
auto rt_NO = []{puts("NO");};
auto rt_No = []{puts("No");};
namespace IO {
#define isdigit(x) (x >= '0' && x <= '9')
inline char gc() {
return getchar();
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline void read(T &x) {
double tmp = 1;
bool sign = 0;
x = 0;
char ch = gc();
for(; !isdigit(ch); ch = gc())
if(ch == '-') sign = 1;
for(; isdigit(ch); ch = gc())
x = x * 10 + (ch - '0');
if(ch == '.')
for(ch = gc(); isdigit(ch); ch = gc())
tmp /= 10.0, x += tmp * (ch - '0');
if(sign) x = -x;
}
inline void read(char *s) {
char ch = gc();
for(; blank(ch); ch = gc());
for(; !blank(ch); ch = gc())
*s++ = ch;
*s = 0;
}
inline void read(char &c) {
for(c = gc(); blank(c); c = gc());
}
inline void push(const char &c) {
putchar(c);
}
template <class T>
inline void print(T x) {
if(x < 0) {
x = -x;
push('-');
}
static T sta[35];
T top = 0;
do {
sta[top++] = x % 10;
x /= 10;
} while(x);
while(top)
push(sta[--top] + '0');
}
template <class T>
inline void print(T x, char lastChar) {
print(x);
push(lastChar);
}
}
using namespace IO;
int m,a[500010],b[500010];
void solve(){
read(m);
rep(i,1,m)read(a[i]);
rep(i,1,m)read(b[i]);
int flag=0,pos=0,ans=0;
rep(i,1,m)if(a[i])pos=i;
nrep(i,m,1){
if(a[i]>b[m-i+1]){
ans+=b[m-i+1];
a[i-1]+=a[i]-b[m-i+1];
b[m-i+1]=0;
if(flag)flag=2;
else flag=1;
}
else{
ans+=a[i];
b[m-i+1]-=a[i];
if(flag)flag=2;
}
}
ans+=b[m];
rep(i,1,m-1)if(b[i]&&pos>m-i+1)flag=2;
if(flag<2)--ans;
print(ans,'\n');
}
signed main() {
clock_t c1 = clock();
#ifdef LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
//------------------------------------------------------------------
int t;read(t);while(t--)solve();
//------------------------------------------------------------------
end:
std::cerr << "Time : " << clock() - c1 << " ms" << std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5704kb
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: 5ms
memory: 5708kb
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:
1 -1 4 -1 3 3 3 1 -1 -1 1 1 3 0 3 0 0 0 0 0 0 0 4 1 3 1 0 2 3 2 1 3 0 -1 2 0 0 1 1 0 0 3 3 3 1 2 2 -1 1 2 2 2 0 3 1 2 1 1 0 1 0 4 0 0 2 2 0 3 3 -1 2 0 1 -1 1 1 1 2 0 3 4 0 2 4 -1 1 1 0 0 -1 3 1 3 -1 2 0 4 3 3 0 1 1 1 1 3 1 1 -1 0 -1 1 -1 3 2 2 0 2 1 1 1 2 -1 0 2 4 1 3 3 2 2 2 -1 2 0 0 1 3 1 3 1 -1 2...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'