Submission #498637

# Submission time Handle Problem Language Result Execution time Memory
498637 2021-12-26T02:38:19 Z RambaXGorilla Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
38 ms 5208 KB
#include<cstdio>
#include<algorithm>
#include<utility>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair <int,int> ii;
#define pq priority_queue
const int modNum = 1000000007;
int N;
int heights[100010];
int widths[100010];
ll prefs[100010];
int smaller[100010];
pq <ii> big;
int form(ll a, ll b){
    ll nums[] = {a, b, a + 1, b + 1};
    for(int i = 0;i < 4;i++){
        if(!(nums[i] % 2)){
            nums[i] /= 2;
        }
        nums[i] %= modNum;
    }
    ll prod = 1;
    for(int i = 0;i < 4;i++){
        prod *= nums[i];
        prod %= modNum;
    }
    return prod;
}
int main(){
    scanf("%d",&N);
    for(int i = 0;i < N;i++){
        scanf("%d",&heights[i]);
    }
    heights[N] = 0;
    prefs[0] = 0;
    for(int i = 0;i < N;i++){
        scanf("%d",&widths[i]);
        prefs[i + 1] = prefs[i] + widths[i];
    }
    for(int i = 0;i < N + 1;i++){
        while(!big.empty() && big.top().first > heights[i]){
            smaller[big.top().second] = i;
            big.pop();
        }
        big.push(ii(heights[i], i));
    }
    int total = 0;
    for(int i = 0;i < N;i++){
        int bott = 0;
        if(i > 0){
            bott = heights[i - 1];
        }
        int curr = i;
        int last;
        while(curr < N){
            last = curr;
            curr = smaller[curr];
            if(heights[last] <= bott){
                break;
            }
            total += (form(heights[last], prefs[curr] - prefs[i]) - form(max(heights[curr], bott), prefs[curr] - prefs[i]) + modNum) % modNum;
            total %= modNum;
        }
    }
    printf("%d",total);
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
fancyfence.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d",&heights[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
fancyfence.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%d",&widths[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 17 ms 2176 KB Output is correct
4 Correct 31 ms 4428 KB Output is correct
5 Correct 32 ms 3920 KB Output is correct
6 Correct 33 ms 3476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 4 ms 836 KB Output is correct
3 Correct 19 ms 2656 KB Output is correct
4 Correct 34 ms 5016 KB Output is correct
5 Correct 37 ms 5124 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 4 ms 800 KB Output is correct
4 Correct 19 ms 2716 KB Output is correct
5 Correct 35 ms 5020 KB Output is correct
6 Correct 37 ms 5208 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 4 ms 856 KB Output is correct
9 Correct 18 ms 2716 KB Output is correct
10 Correct 38 ms 4884 KB Output is correct
11 Correct 38 ms 5048 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 264 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 280 KB Output is correct
7 Correct 0 ms 288 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 288 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 280 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 0 ms 288 KB Output is correct
10 Correct 1 ms 280 KB Output is correct
11 Correct 19 ms 2092 KB Output is correct
12 Correct 31 ms 4420 KB Output is correct
13 Correct 34 ms 3892 KB Output is correct
14 Correct 33 ms 3536 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 3 ms 800 KB Output is correct
17 Correct 17 ms 2668 KB Output is correct
18 Correct 33 ms 5016 KB Output is correct
19 Correct 36 ms 5124 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 4 ms 812 KB Output is correct
22 Correct 20 ms 2768 KB Output is correct
23 Correct 37 ms 4920 KB Output is correct
24 Correct 37 ms 5000 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 4 ms 688 KB Output is correct
32 Correct 17 ms 2116 KB Output is correct
33 Correct 17 ms 2132 KB Output is correct
34 Correct 32 ms 3880 KB Output is correct
35 Correct 34 ms 3904 KB Output is correct
36 Correct 35 ms 4292 KB Output is correct
37 Correct 35 ms 4120 KB Output is correct
38 Correct 0 ms 284 KB Output is correct
39 Correct 33 ms 4156 KB Output is correct
40 Correct 32 ms 4136 KB Output is correct
41 Correct 34 ms 4276 KB Output is correct
42 Correct 34 ms 4588 KB Output is correct