# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
945600 | 2024-03-14T05:30:51 Z | salmon | Fancy Fence (CEOI20_fancyfence) | C++14 | 38 ms | 6272 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]; mal += (sise[a] * (sise[a] + 1)/2); sise[a] %= mod; 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); } /* 1 1000 1000 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 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 | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2648 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 16 ms | 3792 KB | Output is correct |
4 | Correct | 30 ms | 5820 KB | Output is correct |
5 | Correct | 31 ms | 5496 KB | Output is correct |
6 | Correct | 29 ms | 5072 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 4 ms | 2776 KB | Output is correct |
3 | Correct | 16 ms | 4284 KB | Output is correct |
4 | Correct | 34 ms | 6100 KB | Output is correct |
5 | Correct | 36 ms | 6092 KB | Output is correct |
6 | Correct | 1 ms | 2392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 4 ms | 2776 KB | Output is correct |
4 | Correct | 17 ms | 4360 KB | Output is correct |
5 | Correct | 33 ms | 6268 KB | Output is correct |
6 | Correct | 32 ms | 6084 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 4 ms | 2776 KB | Output is correct |
9 | Correct | 19 ms | 4304 KB | Output is correct |
10 | Correct | 31 ms | 6252 KB | Output is correct |
11 | Correct | 32 ms | 6092 KB | Output is correct |
12 | Correct | 1 ms | 2396 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 | 0 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2392 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 | 2404 KB | Output is correct |
9 | Correct | 1 ms | 2396 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 | 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 | 2396 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 | 0 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 | 0 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 | 16 ms | 3776 KB | Output is correct |
12 | Correct | 30 ms | 5836 KB | Output is correct |
13 | Correct | 30 ms | 5436 KB | Output is correct |
14 | Correct | 29 ms | 5072 KB | Output is correct |
15 | Correct | 1 ms | 2392 KB | Output is correct |
16 | Correct | 4 ms | 2776 KB | Output is correct |
17 | Correct | 16 ms | 4268 KB | Output is correct |
18 | Correct | 32 ms | 6084 KB | Output is correct |
19 | Correct | 32 ms | 6080 KB | Output is correct |
20 | Correct | 1 ms | 2392 KB | Output is correct |
21 | Correct | 4 ms | 2772 KB | Output is correct |
22 | Correct | 16 ms | 4280 KB | Output is correct |
23 | Correct | 31 ms | 6080 KB | Output is correct |
24 | Correct | 32 ms | 6272 KB | Output is correct |
25 | Correct | 0 ms | 2396 KB | Output is correct |
26 | Correct | 1 ms | 2488 KB | Output is correct |
27 | Correct | 1 ms | 2396 KB | Output is correct |
28 | Correct | 1 ms | 2396 KB | Output is correct |
29 | Correct | 1 ms | 2396 KB | Output is correct |
30 | Correct | 4 ms | 2776 KB | Output is correct |
31 | Correct | 4 ms | 2776 KB | Output is correct |
32 | Correct | 18 ms | 3540 KB | Output is correct |
33 | Correct | 18 ms | 3692 KB | Output is correct |
34 | Correct | 35 ms | 5072 KB | Output is correct |
35 | Correct | 36 ms | 5068 KB | Output is correct |
36 | Correct | 36 ms | 5072 KB | Output is correct |
37 | Correct | 38 ms | 5072 KB | Output is correct |
38 | Correct | 1 ms | 2392 KB | Output is correct |
39 | Correct | 38 ms | 5068 KB | Output is correct |
40 | Correct | 35 ms | 5068 KB | Output is correct |
41 | Correct | 31 ms | 5072 KB | Output is correct |
42 | Correct | 32 ms | 5588 KB | Output is correct |