Submission #1165365

#TimeUsernameProblemLanguageResultExecution timeMemory
1165365SmuggingSpunFancy Fence (CEOI20_fancyfence)C++20
28 / 100
15 ms1096 KiB
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
typedef long long ll;
const int lim = 1e5 + 5;
const int mod = 1e9 + 7;
void add(int& a, int b){
    if((a += b) >= mod){
        a -= mod;
    }
}
int f(ll N){
    return ((N & 1LL) ? N % mod * (((N + 1) >> 1LL) % mod) : (N >> 1LL) % mod * ((N + 1) % mod)) % mod;
}
int n, h[lim], w[lim];
namespace sub3{
    void solve(){
        int ans = f(accumulate(w + 1, w + n + 1, 0LL));
        ll N = 0;
        for(int i = 1; i <= n; i++){
            if(h[i] == 2){
                N += w[i];
            }
            else{
                add(ans, (f(N) << 1) % mod);
                N = 0;
            }
        }
        cout << (ans + ((f(N) << 1) % mod)) % mod;
    }
}
namespace sub4{
    void solve(){
        cout << 1LL * f(accumulate(w + 1, w + n + 1, 0LL)) * f(h[1]) % mod;
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
    }
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> w[i];
    }
    if(*max_element(h + 1, h + n + 1) < 3){
        sub3::solve();
    }
    else if(*min_element(h + 1, h + n + 1) == *max_element(h + 1, h + n + 1)){
        sub4::solve();
    }
}

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...