Submission #854405

#TimeUsernameProblemLanguageResultExecution timeMemory
854405pliamFancy Fence (CEOI20_fancyfence)C++17
0 / 100
1 ms456 KiB
#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)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
fancyfence.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%lld",&h[i]);
      |         ~~~~~^~~~~~~~~~~~~~
fancyfence.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%lld",&w[i]);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...