답안 #945599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945599 2024-03-14T05:29:40 Z salmon Fancy Fence (CEOI20_fancyfence) C++14
12 / 100
36 ms 5876 KB
#include <bits/stdc++.h>
using namespace std;

int N;
priority_queue<pair<long long int,int>> pq;
long long int h[100100];
long long int w[100100];
int parent[100100];
long long int sise[100100];
long long int mal = 0;
long long int mod = 1'000'000'007;
bool a[100100];
long long int ans = 0;

int root(int i){
    if(parent[i] == i) return i;
    return parent[i] = root(parent[i]);
}

void connect(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return;

    mal -= (sise[a] * (sise[a] + 1)/2) + (sise[b] * (sise[b] + 1)/2);
    sise[a] += sise[b];
    sise[a] %= mod;
    mal += (sise[a] * (sise[a] + 1)/2);
    mal %= mod;
    parent[b] = a;
}

int main(){
    scanf(" %d",&N);

    for(int i = 0; i < N; i++){
        parent[i] = i;

        scanf(" %lld",&h[i]);
        pq.push(make_pair(h[i],i));
        a[i] = false;
    }

    pq.push({0,N});

    for(int i = 0; i < N; i++){
        scanf(" %lld",&w[i]);
        sise[i] = w[i];
    }


    long long int ph = 0;

    while(!pq.empty()){
        long long int h1 = pq.top().first;
        int it = pq.top().second;
        pq.pop();
        //printf("%lld ",mal);

        if(mal != 0){
            ans += (ph * (ph + 1) / 2 - h1 * (h1 + 1) / 2) % mod * mal;
            ans %= mod;
        }

        ph = h1;

        a[it] = true;
        mal += sise[it] * (sise[it] + 1 )/2;
        mal %= mod;

        if(it < N - 1 && a[it + 1]){
            connect(it, it + 1);
        }
        if(it > 0 && a[it - 1]){
            connect(it, it - 1);
        }
    }

    printf("%lld",ans);
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf(" %d",&N);
      |     ~~~~~^~~~~~~~~~
fancyfence.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf(" %lld",&h[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
fancyfence.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         scanf(" %lld",&w[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 2392 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 17 ms 3792 KB Output is correct
4 Correct 29 ms 5876 KB Output is correct
5 Correct 31 ms 5316 KB Output is correct
6 Incorrect 30 ms 4988 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 4 ms 2776 KB Output is correct
3 Incorrect 16 ms 4300 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 4 ms 2880 KB Output is correct
4 Incorrect 16 ms 4284 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 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 15 ms 3792 KB Output is correct
12 Correct 30 ms 5876 KB Output is correct
13 Correct 34 ms 5572 KB Output is correct
14 Incorrect 36 ms 5072 KB Output isn't correct
15 Halted 0 ms 0 KB -