답안 #628739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628739 2022-08-13T16:14:08 Z a_aguilo Fancy Fence (CEOI20_fancyfence) C++14
12 / 100
74 ms 340 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+1;
    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;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 67 ms 312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 69 ms 300 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 69 ms 300 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 74 ms 304 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 67 ms 312 KB Output isn't correct
3 Halted 0 ms 0 KB -