#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;cin>>n;
vector<pair<int,int>> v;
int h=0,w=0,wt=0;
int hh[10005],ww[10005];
for(int i=0;i<n;i++){cin>>hh[i];}
for(int i=0;i<n;i++)cin>>ww[i];
for(int j=0;j<n;j++){
h=hh[j];
w=ww[j];
if(h==2){
if(!v.empty()){
if(v.back().second==wt){
int temp=v.back().first;
v.pop_back();
v.push_back({temp,wt+w});}
else v.push_back({wt,wt+w});
}
else{
v.push_back({wt,wt+w});
}
}
wt+=w;
}
int f[wt+1];
f[0]=0;
for(int i=1;i<=wt;i++){
f[i]=f[i-1]+i;
}
int ans=f[wt];
for(auto i:v){
int t=i.second-i.first;
ans+=f[t]*2;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
132 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Runtime error |
133 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
122 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Runtime error |
127 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Runtime error |
124 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
132 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |