# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
854405 | pliam | Fancy Fence (CEOI20_fancyfence) | C++17 | 1 ms | 456 KiB |
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>
using namespace std;
#define MAXN 100005
typedef long long ll;
#define MOD (ll)1e9+7
#define INF (ll)2e9
/*
We have only height 1 and 2
We need to find all the consequtive ranges of 1 and 2
*/
int N, L;
ll h[MAXN], w[MAXN], sumw;
vector<ll> l1, l2;//lengths of ranges 1 and 2
int main(){
scanf("%d",&N);
for(int i=1;i<=N;i++){
scanf("%lld",&h[i]);
}
for(int i=1;i<=N;i++){
scanf("%lld",&w[i]);
sumw+=w[i];
if(h[i]==h[i-1]){
//existing range
if(h[i]==1){
l1.back()+=w[i];
}else{
l2.back()+=w[i];
}
}else{
//new range
if(h[i]==1){
l1.push_back(w[i]);
}else{
l2.push_back(w[i]);
}
}
}
ll ans=0;
ans+=(sumw*(sumw+1))/2LL;
for(ll l:l2){
ans+=l*(l+1);
}
printf("%lld\n", ans);
}
Compilation message (stderr)
# | 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... |