답안 #930650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930650 2024-02-20T08:48:58 Z LucaIlie Fancy Fence (CEOI20_fancyfence) C++17
30 / 100
58 ms 3256 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 lgPut( int x, int n ) {
    if ( n == 0 )
        return 1;

    int p = lgPut( x, n / 2 );
    p = (long long)p * p % MOD;
    if ( n % 2 == 1 )
        p = (long long)p * x % MOD;

    return p;
}

const int inv2 = (MOD + 1) / 2;
int nchoose2( int n ) {
    return (long long)n * (n + 1) % MOD * inv2 % MOD;
}

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++ ) {
        while ( !s.empty() && h[i] <= h[s.back()] ) {
            sum = (sum - nchoose2( h[i] ) % MOD * p[s.back()] % MOD + MOD) % MOD;
            p[i] = (p[i] + p[s.back()]) % MOD;
            s.pop_back();
        }
        s.push_back( i );

        sum = (sum + (long long)nchoose2( h[i] ) * p[i]) % MOD;
        ans = (ans + (long long)nchoose2( h[i] ) % MOD * nchoose2( w[i] )) % MOD;
        ans = (ans + (long long)sum * w[i] % MOD) % MOD;
        sum = (sum + (long long)nchoose2( h[i] ) * w[i]) % MOD;
    }

    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 348 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 29 ms 1756 KB Output is correct
4 Correct 57 ms 2640 KB Output is correct
5 Correct 58 ms 2644 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 6 ms 564 KB Output is correct
4 Correct 34 ms 1896 KB Output is correct
5 Correct 56 ms 2672 KB Output is correct
6 Correct 58 ms 2640 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 29 ms 1896 KB Output is correct
10 Correct 54 ms 3256 KB Output is correct
11 Correct 56 ms 3080 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -