QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#143053 | #149. Peru | tatyam# | Compile Error | / | / | C++17 | 2.3kb | 2023-08-20 14:11:05 | 2024-09-10 16:42:35 |
Judging History
你现在查看的是最新测评结果
- [2024-09-10 16:42:35]
- 管理员手动重测本题所有提交记录
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-07-04 01:50:02]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-08-20 14:11:05]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LLONG_MAX / 4;
bool chmin(ll& a, ll b) { if(a <= b) return 0; a = b; return 1; }
/*
前から 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) break;
chmin(dp[k], dp[i] + S[j]);
if(i && k == nxt[i - 1]) break;
j = k;
}
}
ll ans = 0;
for(ll i = 1; i <= N; i++) {
ans *= 23;
ans += dp[i];
ans %= MOD;
}
return ans;
}
static int s[2500005];
static int n, k;
int main(){
cin>> n >> k;
for(int i = 0; i < n; i++){
cin>> s[i];
}
int ans = solve(n, k, s);
cout<< ans <<"\n";
return 0;
}
詳細信息
implementer.cpp: In function ‘char nextch()’: implementer.cpp:15:31: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | if (pos == BUF_SIZE) fread(buf, BUF_SIZE, 1, fin), pos = 0; | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~ /usr/bin/ld: /tmp/ccFa8VZA.o: in function `main': answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/cceNWuay.o:implementer.cpp:(.text.startup+0x0): first defined here collect2: error: ld returned 1 exit status