답안 #906581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906581 2024-01-14T13:49:59 Z Ludissey Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
31 ms 6004 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
int n,m;
int mod=1e9+7;
int MOD(int x) {
    return (x+mod)%mod;
}
int clc(int x, int y) {
    x=MOD(x);
    y=MOD(y); 
    return (((((x*(x+1)))/(long long)2)%mod)*((((y*(y+1)))/(long long)2)%mod))%mod; //non cest bon 
}
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    vector<int> h(n+1);
    vector<int> w(n+1);
    int totalw=0;
    for (int i = 1; i <= n; i++) cin>>h[i];
    for (int i = 1; i <= n; i++) cin >> w[i];
    h[0]=0;
    stack<pair<int,int>> stck;
    int outp=0;
    stck.push({h[1],w[1]});
    for (int i = 2; i <= n; i++)
    {
        int hght=stck.top().first;
        int wdht=stck.top().second;
        stck.pop();
        if(hght==h[i]) {
            wdht+=w[i];
            stck.push({hght, wdht});
        }
        else if(hght<h[i]){
            stck.push({hght, wdht});
            stck.push({h[i], w[i]});
        }else{
            bool b=true;
            vector<pair<int,int>> sb4;
            int copyw=w[i];
            while(hght>h[i]){
                w[i]=(w[i]+wdht)%mod;
                sb4.push_back({wdht,hght});
                if(!b) stck.pop();
                if(stck.empty()) break;
                b=false;
                hght=stck.top().first;
                wdht=stck.top().second;
            }
            int totw=w[i]-copyw;
            int last=0;
            for (int j = sb4.size()-1; j >= 0; j--)
            {
                int height=sb4[j].second, width=sb4[j].first;
                int side1=clc(totw,height)-clc(totw,last);
                last=height;
                side1=MOD(side1); // 
                outp=MOD(outp+side1); //jai pas compris
                totw-=width;
            }
            int min=clc(MOD(w[i]-copyw),h[i]);
            outp=MOD(outp-min);
            stck.push({h[i], w[i]});
        }
    }
    h.clear();
    w.clear();
    int newN=stck.size();
    h.resize(newN);
    w.resize(newN);
    totalw=0;
    for (int i = newN; i > 0; i--)
    {
        h[i]=stck.top().first;
        w[i]=stck.top().second;
        totalw=(totalw+w[i])%mod;
        stck.pop();
    }
    h[0]=0;
    for (int i = 1; i <= newN; i++)
    {
        int side1=clc(totalw,h[i])-clc(totalw,h[i-1]);
        side1=MOD(side1); // 
        outp=MOD(outp+side1); //jai pas compris
        totalw-=w[i];
    }
    cout << outp << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 9 ms 1248 KB Output is correct
4 Correct 16 ms 2136 KB Output is correct
5 Correct 17 ms 2444 KB Output is correct
6 Correct 14 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 9 ms 1116 KB Output is correct
4 Correct 17 ms 2036 KB Output is correct
5 Correct 18 ms 2044 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 8 ms 1116 KB Output is correct
5 Correct 16 ms 1884 KB Output is correct
6 Correct 17 ms 2044 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 612 KB Output is correct
9 Correct 10 ms 1368 KB Output is correct
10 Correct 25 ms 3676 KB Output is correct
11 Correct 29 ms 3668 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 464 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 500 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 9 ms 1884 KB Output is correct
12 Correct 16 ms 2860 KB Output is correct
13 Correct 18 ms 3136 KB Output is correct
14 Correct 15 ms 2904 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 9 ms 1884 KB Output is correct
18 Correct 17 ms 3280 KB Output is correct
19 Correct 18 ms 3164 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 3 ms 856 KB Output is correct
22 Correct 11 ms 2140 KB Output is correct
23 Correct 26 ms 4852 KB Output is correct
24 Correct 25 ms 4964 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 13 ms 1884 KB Output is correct
33 Correct 15 ms 2228 KB Output is correct
34 Correct 27 ms 3676 KB Output is correct
35 Correct 26 ms 3676 KB Output is correct
36 Correct 28 ms 3932 KB Output is correct
37 Correct 31 ms 3924 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 27 ms 3932 KB Output is correct
40 Correct 30 ms 3952 KB Output is correct
41 Correct 30 ms 4436 KB Output is correct
42 Correct 29 ms 6004 KB Output is correct