Submission #830386

# Submission time Handle Problem Language Result Execution time Memory
830386 2023-08-19T05:15:07 Z Warinchai Fancy Fence (CEOI20_fancyfence) C++14
12 / 100
14 ms 596 KB
#include<bits/stdc++.h>
using namespace std;
long long h[100005];
long long w[100005];
long long md=1e9+7;
struct block{
    long long h,w;
    block(long long hh=0,long long ww=0){
        h=hh;
        w=ww;
    }
};
long long calc(block x){
    long long ans=x.h*(x.h+1)/2;
    ans%=md;
    long long ans1=x.w*(x.w+1)/2;
    ans1%=md;
    long long ans2=(ans*ans1)%md;
    return ans2;
}
vector<long long>v;
vector<block>info;
vector<block>tmp;
map<int,int>mp;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>h[i];
        if(mp[h[i]]==0){
            mp[h[i]]=1;
            v.push_back(h[i]);
            //cout<<h[i]<<endl;
        }
    }
    //cout<<endl;
    //cout<<v.size()<<endl;
    sort(v.begin(),v.end(),greater<int>());
    for(int i=1;i<=n;i++){
        cin>>w[i];
    }
    long long ans=0;
    /*for(int i=0;i<v.size();i++){
        cout<<v[i]<<endl;
    }
    cout<<endl;*/
    for(int i=1;i<=n;i++){
        info.push_back(block(h[i],w[i]));
    }
    for(int i=0;i<v.size();i++){
        long long h=v[i];
        tmp.clear();
        //cout<<h<<":"<<endl;
        for(int j=0;j<info.size();j++){
            if(info[j].h>=h){
                if(i!=0&&info[j-1].h>=h){
                    block z=tmp.back();
                    tmp.pop_back();
                    tmp.push_back(block(h,z.w+info[j].w));
                }else{
                    tmp.push_back(block(h,info[j].w));
                }
            }else{
                tmp.push_back(info[j]);
            }
        }
        //cout<<"blocks"<<endl;
        for(int j=0;j<tmp.size();j++){
            //cout<<tmp[j].h<<" "<<tmp[j].w<<endl;
            if(tmp[j].h>=h){
                ans+=calc(tmp[j]);
                ans%=md;
            }
        }
        for(int j=0;j<info.size();j++){
            if(info[j].h>h){
                ans+=md;
                ans-=calc(block(h,info[j].w));
                ans%=md;
            }
        }
        //cout<<"ans:"<<ans<<endl;
        info.clear();
        for(int i=0;i<tmp.size();i++){
            info.push_back(tmp[i]);
        }
    }
    cout<<ans;

}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
fancyfence.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<block>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int j=0;j<info.size();j++){
      |                     ~^~~~~~~~~~~~
fancyfence.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<block>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int j=0;j<tmp.size();j++){
      |                     ~^~~~~~~~~~~
fancyfence.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<block>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for(int j=0;j<info.size();j++){
      |                     ~^~~~~~~~~~~~
fancyfence.cpp:86:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<block>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for(int i=0;i<tmp.size();i++){
      |                     ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 14 ms 472 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 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 596 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 336 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 Incorrect 14 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 Incorrect 14 ms 472 KB Output isn't correct
3 Halted 0 ms 0 KB -