Submission #830428

# Submission time Handle Problem Language Result Execution time Memory
830428 2023-08-19T06:30:05 Z Warinchai Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
long long h[200005];
long long w[200005];
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;
}
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];
    }
    for(int i=1;i<=n;i++){
        cin>>w[i];
    }
    vector<block>v;
    v.push_back(block(h[1],w[1]));
    for(int i=2;i<=n;i++){
        if(h[i]==v.back().h){
            long long tw=v.back().w;
            v.pop_back();
            v.push_back(block(h[i],tw+w[i]));
        }else{
            v.push_back(block(h[i],w[i]));
        }
    }
    /*for(int i=0;i<v.size();i++){
        cout<<v[i].h<<' '<<v[i].w<<endl;
    }*/
    long long ans=0;
    long long aw=0;
    for(int i=0;i<v.size();i++){
        if(v[i].h==2){
            ans+=calc(v[i]);
            ans-=calc(block(1,v[i].w));
            //cout<<calc(v[i])<<" "<<calc(block(1,v[i].w))<<" ";
            ans%=md;
        }
        aw+=v[i].w;
    }
    ans+=calc(block(1,aw));
    ans%=md;
    cout<<ans;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<block>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 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 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Incorrect 1 ms 340 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 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -