Submission #1167404

#TimeUsernameProblemLanguageResultExecution timeMemory
1167404henriessFancy Fence (CEOI20_fancyfence)C++20
15 / 100
14 ms1864 KiB
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    long long n;
    cin >> n;
    vector<long long> h(n), w(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }
    
    // Subtask 3: all heights are equal, so h[0] is the common height.
    long long totalwidth = 0;
    for (int i = 0; i < n; i++){
        totalwidth += w[i];
        totalwidth %= MOD; // optional: to keep the number smaller if widths are huge
    }
    
    // Using __int128 to avoid overflow in multiplication.
    __int128 t = totalwidth;
    long long n1 = (long long)((t * (t + 1)) % MOD);
    
    __int128 h_val = h[0];
    long long n2 = (long long)((h_val * (h_val + 1)) % MOD);
    
    long long inv4 = 250000002; // Modular inverse of 4 mod MOD
    long long ans = ((n1 * n2) % MOD * inv4) % MOD;
    
    cout << ans;
    return 0;
}
#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...