Submission #854405

# Submission time Handle Problem Language Result Execution time Memory
854405 2023-09-27T10:14:18 Z pliam Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 456 KB
#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

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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 456 KB Output isn't correct
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 344 KB Output is correct
2 Incorrect 0 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -