답안 #868582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868582 2023-10-31T22:23:03 Z mariaclara Fancy Fence (CEOI20_fancyfence) C++17
30 / 100
1000 ms 4272 KB
#pragma GCC optimize "Ofast"
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef tuple<ll,ll,ll> trio;
typedef pair<int,int> pii;
const int MAXN = 1e5+10;
const ll MOD = 1e9+7;
#define all(x) x.begin(), x.end()
#define mk make_pair
#define pb push_back
#define f first
#define s second

ll n, resp, h[MAXN], w[MAXN], ant[MAXN], pos[MAXN], pw[MAXN];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;

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

    for(int i = 1; i <= n; i++)
        cin >> w[i], pw[i] = pw[i-1] + w[i];

    for(int i = 1; i <= n; i++)
        ant[i] = i-1, pos[i] = i+1;

    for(int i = 1; i <= n; i++) {
        while(h[i] < h[ant[i]]) ant[i] = ant[ant[i]];
        while(h[i] <= h[pos[i]]) pos[i] = pos[pos[i]];
    }

    for(int i = 1; i <= n; i++) {
        ll l = ant[i]+1, r = pos[i]-1;
        ll tot = (((pw[r]-pw[l-1]+1)%MOD) * ((pw[r]-pw[l-1])%MOD))/2;
        ll casoA = (((pw[r]-pw[i]+1)%MOD) * ((pw[r]-pw[i])%MOD))/2;
        ll casoB = (((pw[i-1]-pw[l-1]+1)%MOD) * ((pw[i-1]-pw[l-1])%MOD))/2;
        resp +=  ((tot%MOD - casoA%MOD - casoB%MOD)%MOD) * ((h[i] * (h[i]+1) / 2)%MOD);
        resp %= MOD;
    }

    cout << (resp + MOD) % MOD;
}
// g++ -std=c++17 clara.cpp -o clara
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 785 ms 3664 KB Output is correct
4 Execution timed out 1101 ms 4272 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 79 ms 2744 KB Output is correct
3 Execution timed out 1082 ms 3420 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 79 ms 2728 KB Output is correct
4 Execution timed out 1053 ms 3416 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 792 ms 3464 KB Output is correct
12 Execution timed out 1014 ms 4184 KB Time limit exceeded
13 Halted 0 ms 0 KB -