답안 #930432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930432 2024-02-19T15:30:08 Z LucaIlie Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 440 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5;
const int MOD = 1e9 + 7;
int h[MAX_N], w[MAX_N], p[MAX_N];
vector<int> s;

int main() {
    int n;

    cin >> n;
    for ( int i = 0; i < n; i++ )
        cin >> h[i];
    for ( int i = 0; i < n; i++ )
        cin >> w[i];


    int ans = 0, sum = 0;
    for ( int i = 0; i < n; i++ ) {
        p[i] = w[i];
        while ( !s.empty() && h[i] <= h[s.back()] ) {
            sum = (sum - (long long)h[i] * p[s.back()] + MOD) % MOD;
            p[i] = (p[i] + p[s.back()]) % MOD;
            s.pop_back();
        }
        s.push_back( i );
        ans = (ans + ((long long)h[i] * (h[i] + 1) / 2 % MOD) * ((long long)w[i] * (w[i] + 1) / 2) % MOD) % MOD;
        ans = (ans + sum * w[i]) % MOD;
        sum = (sum + (long long)h[i] * w[i]) % MOD;
    }

    cout << ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -