답안 #855506

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855506 2023-10-01T11:21:44 Z sofijavelkovska Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
2 ms 624 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=1e5, MOD=1e9+7;

int h[MAXN], w[MAXN];

bool compare(int x, int y)
{
    return h[x]<=h[y];
}

long long outer(int i, long long sum)
{
    return (long long)h[i]*w[i]%MOD*sum%MOD;
}

long long inner(int i)
{
    long long rectangles=0;
    rectangles=(rectangles+(long long)h[i]*w[i])%MOD;
    rectangles=(rectangles+h[i]*((long long)w[i]*(w[i]-1)/2%MOD)%MOD)%MOD;
    rectangles=(rectangles+w[i]*((long long)h[i]*(h[i]-1)/2%MOD)%MOD)%MOD;
    rectangles=(rectangles+((long long)h[i]*(h[i]-1)/2%MOD)*((long long)w[i]*(w[i]-1)/2%MOD)%MOD)%MOD;

    return rectangles;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, x, left, right, i;
    long long leftsum, rightsum, total=0;
    set<int> processed;
    cin >> n;
    int index[i];
    long long prefixsum[n];
    for (i=0; i<n; i++)
        cin >> h[i];
    for (i=0; i<n; i++)
        cin >> w[i];
    for (i=0; i<n; i++)
        index[i]=i;
    sort(index, index+n, compare);
    prefixsum[0]=w[0];
    for (i=1; i<n; i++)
        prefixsum[i]=prefixsum[i-1]+w[i];
    processed.insert(-1);
    processed.insert(n);
    for (i=0; i<n; i++)
    {
        x=index[i];
        auto it=processed.lower_bound(x);
        right=*it;
        it--;
        left=*it;
        rightsum=(prefixsum[right-1]-prefixsum[x])%MOD;
        leftsum=(prefixsum[x]-w[x]-(prefixsum[left+1]-w[left+1]))%MOD;
        total=(total+outer(i, leftsum)+outer(i, rightsum)+inner(i))%MOD;
        processed.insert(x);
    }
    cout << total;

    return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:34:28: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
   34 |     int n, x, left, right, i;
      |                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 572 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 624 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 496 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 2 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 572 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -