QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#143051#149. Perutatyam#0 53ms71532kbC++172.0kb2023-08-20 14:07:362024-09-10 16:42:35

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 16:42:35]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:53ms
  • 内存:71532kb
  • [2024-07-04 01:50:00]
  • 评测
  • [2023-08-20 14:07:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LLONG_MAX / 4;

/*
 前から DP?それとも最大値分割?
 前から DP する. dp[最初の生存] = コストの最小値.
 dp は単調増加なので, dp[i-1] から更新できる位置を dp[i] から更新する必要はない.
 A[i] から, 「A[i] より先にある A[i] 以上の最初の要素」に辺を張り, これをたどりながら更新, すでに更新されていたら break して, dp[i+K] を更新
 
 1. A[i] から, 「A[i] より先にある A[i] 以上の最初の要素」に辺を張る (後ろから stack で管理)
 2. max(A[i:i+K]) をスライド最大値で計算
 3. DP する
 */
const ll MOD = 1000000007;
int solve(int N, int K, int* S) {
    vector<ll> nxt = [&]{
        vector<ll> nxt(N);
        vector<pair<ll, ll>> q;
        q.emplace_back(INF, N);
        for(ll i = N; i--; ) {
            while(q.back().first <= S[i]) q.pop_back();
            nxt[i] = q.back().second;
            q.emplace_back(S[i], i);
        }
        return nxt;
    }();
    vector<ll> mx = [&]{
        vector<ll> mx(N);
        deque<pair<ll, ll>> q;
        for(ll i = 0; i < N; i++) {
            if(q.size() && q.front().second <= i - K) q.pop_front();
            while(q.size() && q.back().first <= S[i]) q.pop_back();
            q.emplace_back(S[i], i);
            mx[i] = q.front().first;
        }
        mx.erase(mx.begin(), mx.begin() + K - 1);
        return mx;
    }();
    vector<ll> dp(N + 1, INF);
    dp[0] = 0;
    for(ll i = 0; i < N; i++) {
        if(dp[i] == INF) dp[i] = dp[nxt[i - 1]];
        if(i + K <= N) dp[i + K] = dp[i] + mx[i];
        ll j = i;
        while(j < N) {
            const ll k = nxt[j];
            if(k >= i + K || dp[k] != INF) break;
            dp[k] = dp[i] + S[j];
            j = k;
        }
    }
    ll ans = 0;
    for(ll i = 1; i <= N; i++) {
        ans *= 23;
        ans += dp[i];
        ans %= MOD;
    }
    return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3808kb

input:

2000 170
1054018657 1037445664 1011691297 1009972317 1006506677 1002579733 999792775 999477541 975467893 970302369 968173111 957735623 953086083 938540451 932313113 930563895 924682633 917831575 913506401 908739591 905368525 899452913 894354220 890127447 885923007 583391543 880642788 878397752 87822...

output:

882585867

result:

wrong answer 1st lines differ - expected: '559335223', found: '882585867'

Subtask #2:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 8ms
memory: 15648kb

input:

400000 1000
1999989721 1999987224 1999984551 1999977673 1999977545 1999976801 1999975837 1999972607 1999956301 1999952801 1999942489 1999940593 1999940337 1999936353 1999936273 1999926073 1999925513 1999922980 1999918301 1999912501 1999909301 1999906125 1999902913 1999895622 1999893617 1999885490 19...

output:

266524043

result:

wrong answer 1st lines differ - expected: '677928817', found: '266524043'

Subtask #3:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 53ms
memory: 71532kb

input:

2500000 2000
1073315871 1073250349 1072791751 1072104046 1072071097 1071841833 1071809381 1071710686 1071580105 1071482003 1071383725 1071154701 1070499431 1070335288 1070334157 1069943617 1069681476 1069584279 1069581771 1069322519 1069189353 1069125955 1068832186 1068797487 1068662939 1068565681 1...

output:

285287243

result:

wrong answer 1st lines differ - expected: '12623259', found: '285287243'