Submission #557892

# Submission time Handle Problem Language Result Execution time Memory
557892 2022-05-06T09:17:28 Z DJ035 Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
2 ms 340 KB
#include <bits/stdc++.h>
#define MEM 111111
#define sanic ios_base::sync_with_stdio(0)
#define x first
#define y second
#define pf push_front
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll INF = 1e13+7;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b){
    if(a%b) return gcd(b, a%b);
    return b;
}
ll c2(ll n){
    ll ret = n*(n-1)/2LL;
    ret %= MOD;
    ret += MOD;
    ret %= MOD;
    return ret;
}
ll hp(ll l, ll r){
    ll a=c2(l+1);
    ll b=c2(r+1);
    return ((b-a)%MOD+MOD)%MOD;
}
ll n,m,t,c;
ll h[MEM], w[MEM];
signed main(){
    //sanic; cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> h[i];
    for(int i=0; i<n; i++)
        cin >> w[i];
    stack<pi> s;
    ll ans=0;
    for(int i=0; i<n; i++)
        s.push({h[i], w[i]});
    while(!s.empty()){
        ll h1=s.top().x, w1=s.top().y;
        s.pop();
        ans = (ans+(hp((s.empty()?0:s.top().x), h1)*c2(w1+1))%MOD+MOD)%MOD;
        //cout << h1 << ' ' << w1 << '\n';
        if(s.empty()) break;
        pi ff=s.top();
        s.pop();
        ff.y += w1;
        s.push(ff);
    }
    cout << ans;
}
/*
10
1 3 2 4 2 1 3 5 6 7
2 3 5 4 6 2 3 5 6 7
3
2 3 1
3 1 2
660
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
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 1 ms 212 KB Output is correct
2 Incorrect 1 ms 316 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 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 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -