Submission #592120

# Submission time Handle Problem Language Result Execution time Memory
592120 2022-07-08T14:14:17 Z jasmin Fancy Fence (CEOI20_fancyfence) C++14
40 / 100
1000 ms 5444 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int mod=1e9+7;

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

    //freopen("input1.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    int n;
    cin >> n;
    vector<int> h(n);
    map<int,int> ind; int x=1;
    vector<pair<int, vector<int> > >sorted;
    sorted.push_back({0, {}});
    for(int i=0; i<n; i++){
        cin >> h[i];
        if(ind[h[i]]==0){
            sorted.push_back({h[i], {}});
            ind[h[i]]=x;
            x++;
        }
        sorted[ind[h[i]]].second.push_back(i);
    }
    sort(sorted.begin(), sorted.end());
    reverse(sorted.begin(), sorted.end());
    vector<int> w(n);
    for(int i=0; i<n; i++){
        cin >> w[i];
    }

    vector<int> a(n+1);
    int ans=0;
    for(int i=0; i<(int)sorted.size()-1; i++){
        int h=sorted[i].first;
        int next=sorted[i+1].first;

        vector<int> ele=sorted[i].second;
        for(auto e: ele){
            a[e]=w[e];
        
        }

        int s=0; 
        int mom=(int)0;
        for(int j=0; j<=n; j++){
            if(a[j]==0){
                s+=((mom*(mom+1))/2)%mod;
                mom=0;
            }

            mom+=a[j];
            mom%=mod;
        }

        int factor=((h*(h+1))/2 - (next*(next+1))/2)%mod;
        ans+=(s*factor)%mod;
        ans%=mod;
    }

    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 4 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 9 ms 2636 KB Output is correct
4 Correct 18 ms 5396 KB Output is correct
5 Correct 18 ms 5320 KB Output is correct
6 Correct 17 ms 5368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 11 ms 2400 KB Output is correct
4 Correct 20 ms 4356 KB Output is correct
5 Correct 24 ms 4368 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 11 ms 2412 KB Output is correct
5 Correct 22 ms 4360 KB Output is correct
6 Correct 23 ms 4268 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 375 ms 1988 KB Output is correct
9 Execution timed out 1082 ms 5444 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 4 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 4 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -