답안 #1006941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006941 2024-06-24T10:07:06 Z Hanksburger Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1000 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
long long h[100005], w[100005], mod=1e9+7, inv2=5e8+4;
vector<pair<long long, long long> > vec;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    freopen("1000.txt", "r", stdin);
    long long n, cur=0, ans=0;
    cin >> n;
    for (long long i=1; i<=n; i++)
        cin >> h[i];
    for (long long i=1; i<=n; i++)
        cin >> w[i];
    vec.push_back({-1, 0});
    vec.push_back({0, 0});
    for (long long i=1; i<=n+1; i++)
    {
        while (vec[vec.size()-2].first>=h[i])
        {
            long long x=(cur-vec[vec.size()-1].second+mod)%mod*(cur-vec[vec.size()-1].second+1+mod)%mod*inv2%mod;
            long long y=(vec[vec.size()-1].first+vec[vec.size()-2].first+1)%mod*(vec[vec.size()-1].first-vec[vec.size()-2].first+mod)%mod*inv2%mod;
            ans=(ans+x*y)%mod;
            vec.pop_back();
        }
        if (vec[vec.size()-1].first>h[i])
        {
            long long x=(cur-vec[vec.size()-1].second+mod)%mod*(cur-vec[vec.size()-1].second+1+mod)%mod*inv2%mod;
            long long y=(vec[vec.size()-1].first+h[i]+1)%mod*(vec[vec.size()-1].first-h[i]+mod)%mod*inv2%mod;
            ans=(ans+x*y)%mod;
            vec[vec.size()-1].first=h[i];
        }
        else
            vec.push_back({h[i], cur});
        cur=(cur+w[i])%mod;
    }
    cout << ans;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen("1000.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1037 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1055 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1057 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1042 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1043 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1070 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1037 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -