Submission #628742

# Submission time Handle Problem Language Result Execution time Memory
628742 2022-08-13T16:18:49 Z a_aguilo Fancy Fence (CEOI20_fancyfence) C++14
12 / 100
73 ms 316 KB
#include<bits/stdc++.h>

using namespace std;
typedef vector<int> vi;

const int MOD = 1e9 + 7;

void buildTree(int node, int leftBound, int rightBound, vi& arr, vi& tree){
    if(leftBound > rightBound) return;
    if(leftBound == rightBound) {
        tree[node] = arr[leftBound];
        return;
    }
    int mid = leftBound + (rightBound - leftBound)/2;
    buildTree(2*node, leftBound, mid, arr, tree);
    buildTree(2*node+1, mid+1, rightBound, arr, tree);
    tree[node] = min(tree[2*node], tree[2*node+1]);
}

int getValue(int node, int leftBound, int rightBound, int left, int right, vi& tree){
    if(left > rightBound or right < leftBound) return 1e9+7;
    if(left <= leftBound and right >= rightBound)return tree[node];
    int mid = leftBound + (rightBound - leftBound)/2;
    return min(getValue(2*node, leftBound, mid, left, right, tree), getValue(2*node+1, mid+1, rightBound, left, right, tree));
}

int main(){
    int n;
    long long W;
    cin >> n;
    vi heights(n);
    vi widths(n);
    for(int i = 0; i < n; ++i) cin >> heights[i];
    for(int i = 0; i < n; ++i)cin >> widths[i];

    vi tree(4*n);
    buildTree(1, 0, n-1, heights, tree);

    long long ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i; j < n; ++j){

            int H = getValue(1, 0, n-1, i, j, tree);
            //cout << i << " " << j << " " << H << " " << W << endl;
            long long chooseh = (H*(H+1)/2)%MOD;

            long long choosew;
            if(i == j) choosew = (widths[i]*(widths[i]+1)/2)%MOD;
            else choosew = (widths[i]*widths[j])%MOD;

            ans += (chooseh*choosew)%MOD;
            ans%=MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:29:15: warning: unused variable 'W' [-Wunused-variable]
   29 |     long long W;
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 68 ms 304 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 65 ms 296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 224 KB Output is correct
2 Incorrect 73 ms 316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 66 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 68 ms 304 KB Output isn't correct
3 Halted 0 ms 0 KB -