QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#679344 | #8057. Best Carry Player 4 | gaofeng | WA | 48ms | 9908kb | C++23 | 2.9kb | 2024-10-26 17:24:43 | 2024-10-26 17:25:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF = 0x3f3f3f3f;
const ll INFll = 0x3f3f3f3f3f3f3f3f;
#define endl "\n"
#define x first
#define y second
//vector<vector<int>>adj(N);
int a[N],b[N];
int aa[N],bb[N];
void solve()
{
int m;
cin >> m;
int suma = 0, sumb = 0;
for(int i = 0; i < m; i ++) cin >> a[i], suma += a[i];
for(int j = 0; j < m; j ++) cin >> b[j], sumb += b[j];
int sum = 0, ans = 0;
// s.push({b[m - 1], m - 1});
// for(int i = 0; i < m && ans == 0; i ++) {
// s.push({b[m - i], m - i});
// while(s.size() && s.top().second + i >= m && a[i] && !ans) {
// PII t = s.top(); s.pop();
// int res = min({a[i], t.first, 1});
// a[i] -= res;
// b[t.second] -= res;
// t.first -= res;
// ans += res;
// if(t.first) s.push(t);
// }
// }
// // cout << ans << endl;
// for(int i = 0; i < m; i ++) cout << a[i] << " "; cout << endl;
// for(int i = 0; i < m; i ++) cout << b[i] << " "; cout << endl;
for(int ii = 0; ii < m; ii ++) {
if(a[ii] && b[m - ii]) {
stack<PII> s;
int aans = 0;
for(int i = 0;i < m; i ++) aa[i] = a[i], bb[i] = b[i];
aa[ii] --;
bb[m - ii] --;
for(int i = 0; i < m; i ++) {
if(m - i - 1 >= 0)s.push({bb[m - i - 1], m - i - 1});
while(s.size() && s.top().second + i + 1 >= m && aa[i]) {
PII t = s.top(); s.pop();
int res = min(aa[i], t.first);
aa[i] -= res;
bb[t.second] -= res;
t.first -= res;
aans += res;
if(t.first) s.push(t);
}
}
aans += aa[m - 1] + bb[m - 1];
ans = max(ans, aans + 1);
}
}
// while(s.size())s.pop();
// if(ans) {
// for(int i = 0; i < m; i ++) {
// if(m - i - 1 >= 0)s.push({b[m - i - 1], m - i - 1});
// while(s.size() && s.top().second + i + 1 >= m && a[i]) {
// PII t = s.top(); s.pop();
// int res = min(a[i], t.first);
// a[i] -= res;
// b[t.second] -= res;
// t.first -= res;
// ans += res;
// if(t.first) s.push(t);
// }
// }
// ans += a[m - 1] + b[m - 1];
// }
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cout << setprecision(11) << fixed;
int t;t=1;
cin>>t;
for(int i=1;i<=t;i++){
//printf("Case %d: ",i);
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9908kb
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: 48ms
memory: 9900kb
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 0 3 0 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 0 0 2 3 3 0 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 2 0 1 0 0 2 0 0 0 2 0 1 0 1 0 4 0 0 0 2 0 3 3 0 2 0 0 0 0 1 1 2 0 0 4 0 2 5 0 2 1 0 0 0 3 2 3 0 2 0 4 3 3 0 0 2 0 1 3 1 1 0 0 0 0 0 3 2 0 0 0 0 1 0 1 0 0 0 4 1 0 0 2 0 2 0 2 0 0 0 3 0 3 1 0 2 0 3 0 1 2 0 0 1 ...
result:
wrong answer 6th numbers differ - expected: '3', found: '0'