This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[n],ww[n];
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |