답안 #930331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930331 2024-02-19T11:28:41 Z vjudge1 Fancy Fence (CEOI20_fancyfence) C++17
30 / 100
24 ms 3420 KB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000000007
#define INF 1000000000
#define INF2 2000000000000000000
//#define ll long long
///#define cin fin
///#define cout fout
using namespace std;
double const EPS = 1e-14;
///ofstream fout("herding.out");
///ifstream fin("herding.in");

int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int n; cin >> n; long long h[n], w[n];
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < n; i++) cin >> w[i];
    stack<pair<long long, long long>> st;
    long long ans = 0, nw = 0;
    for(int i = 0; i < n; i++) {
         nw = 0;
        while(!st.empty() && st.top().first > h[i]) {
            pair<long long, long long> now = st.top();
            nw += now.second;
            nw %= mod;
            st.pop();
            ans += (((now.first*(now.first+1))/2%mod) * ((nw*(nw+1))/2%mod)%mod);
            ans %= mod;
            if(!st.empty()) {
                ans -= ((st.top().first*(st.top().first+1))/2%mod) * ((nw*(nw+1))/2%mod)%mod;
                ans += mod;
                ans %= mod;
            }
        }
        if(!st.empty())st.top().second += nw;
        st.push({h[i],w[i]});
    }
    nw = 0;
        while(!st.empty()) {
            pair<long long, long long> now = st.top();
            nw += now.second;
            nw %= mod;
            st.pop();
            ans += (((now.first*(now.first+1))/2%mod) * ((nw*(nw+1))/2%mod)%mod);
            ans %= mod;
            if(!st.empty()) {
                ans -= ((st.top().first*(st.top().first+1))/2%mod) * ((nw*(nw+1))/2%mod)%mod;
                ans += mod;
                ans %= mod;
            }
        }
    cout << ans%mod << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 13 ms 1884 KB Output is correct
4 Correct 20 ms 3416 KB Output is correct
5 Correct 24 ms 3420 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 9 ms 1884 KB Output is correct
5 Correct 18 ms 3420 KB Output is correct
6 Correct 18 ms 3420 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 9 ms 1884 KB Output is correct
10 Correct 17 ms 3420 KB Output is correct
11 Correct 22 ms 3420 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -