답안 #745768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745768 2023-05-21T07:33:29 Z vjudge1 Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
2 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int MOD = 1e9 +7;

int binpow(int a, int b){
    int ans = 1;
    while(b != 0){
        if(b & 1){
            ans = ans * a % MOD;
        }
        a = a * a % MOD;
        b /= 2;
    }
    return ans;
}

signed main() {
    int n;
    cin >> n;
    vector<int> h(n), w(n);
    int cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 0; i < n; i++){
        cin >> w[i];
    }
    int dv = binpow(2, MOD - 2);
    int egy = 0, ketto = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int act1, bn1, bn2;
        if(h[i] == 1){
            ketto = 0;
            act1 = (egy + w[i]) % MOD;
            bn1 = act1 * (act1 + 1) % MOD, bn2 = egy * (egy + 1) % MOD;
            ans = (ans + bn1 * dv % MOD - bn2 * dv % MOD + MOD) % MOD;
            egy = act1;
        }
        else{
            int act1 = (egy + w[i]) % MOD;
            int bn1 = act1 * (act1 + 1) % MOD, bn2 = egy * (egy + 1) % MOD;
            ans = (ans + bn1 * dv % MOD - bn2 * dv % MOD + MOD) % MOD;
            egy = act1;
            act1 = (ketto + w[i]) % MOD;
            bn1 = act1 * (act1 + 1) % MOD, bn2 = ketto * (ketto + 1) % MOD;
            ans = (ans + bn1 - bn2 + MOD) % MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:24:9: warning: unused variable 'cnt' [-Wunused-variable]
   24 |     int cnt = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 2 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -