Submission #868581

# Submission time Handle Problem Language Result Execution time Memory
868581 2023-10-31T22:18:55 Z mariaclara Fancy Fence (CEOI20_fancyfence) C++17
30 / 100
1000 ms 5468 KB
#pragma GCC optimize "O3"
#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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory 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 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 783 ms 4048 KB Output is correct
4 Execution timed out 1043 ms 5468 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 79 ms 2928 KB Output is correct
3 Execution timed out 1042 ms 4440 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 79 ms 2772 KB Output is correct
4 Execution timed out 1076 ms 4440 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2392 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 2512 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 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 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2556 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 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 781 ms 4056 KB Output is correct
12 Execution timed out 1058 ms 5468 KB Time limit exceeded
13 Halted 0 ms 0 KB -