QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#249977 | #6794. Sequence to Sequence | atgc | AC ✓ | 91ms | 4976kb | C++14 | 1.3kb | 2023-11-12 18:56:14 | 2023-11-12 18:56:15 |
Judging History
answer
/*YYC is Thinking Here*/
#include<bits/stdc++.h>
#define mids(l,r) const auto mid = (l + r) >> 1
#define lb(x) (x&-x)
#define ls (x<<1)
#define rs (ls|1)
#define int long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxn = 1e5+10;
int n,x,y,z,ans,a[maxn],b[maxn];
void solve(){
cin>>n;
for(int i = 1;i <= n;++i) cin>>a[i];
for(int i = 1;i <= n;++i) cin>>b[i];
x = y = z = ans = 0;
for(int i = 1;i <= n;++i) {
int a = ::a[i], b = ::b[i];
if(b == 0) {
if(x < a) {
int d = a - x, ad = min(z,d);
x += d, ans += d, y += ad, z -= ad;
// if(d <= z) x += d, y += d, z -= d, ans += d;
// else x += d, y += z, z = 0, ans += d;
}
} else {
if(a == 0) return cout<<"-1\n",void();
x = min(x, a - 1);
y = min(y, b - 1);
if(a - x + y < b) { //should +
int xmv = min(x, b - (a - x + y));
x -= xmv, z += xmv;
int v = b - a + x - y;
y += v, ans += v;
} else {
int ymv = min(y, a - x + y - b);
y -= ymv, z += ymv;
int v = a - x + y - b;
x += v, ans += v;
}
z = min(z, a - x - 1);
}
}
cout<<ans<<'\n';
}
signed main() {
ios::sync_with_stdio(0),cin.tie(0);
int T;cin>>T;while(T--)solve();
}
/*
* I love it all
* Go forward,move forward !
*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3388kb
input:
2 5 1 1 1 1 1 2 0 2 0 2 7 3 1 2 3 2 1 4 2 0 0 0 0 0 2
output:
3 3
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 91ms
memory: 4976kb
input:
110121 5 0 0 0 0 0 1 4 5 4 1 5 1 0 0 0 0 0 6 8 6 1 5 2 0 0 0 0 4 4 1 3 6 5 3 0 0 0 0 5 1 1 7 6 5 4 0 0 0 0 6 8 7 0 8 5 5 0 0 0 0 5 9 7 7 5 5 6 0 0 0 0 9 2 2 8 0 5 7 0 0 0 0 9 4 7 0 9 5 8 0 0 0 0 6 7 3 7 5 5 9 0 0 0 0 4 0 9 1 4 5 0 1 0 0 0 0 6 6 3 0 5 1 1 0 0 0 3 4 3 4 9 5 2 1 0 0 0 0 4 0 1 4 5 3 1 0...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 110121 tokens
Extra Test:
score: 0
Extra Test Passed