답안 #534248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534248 2022-03-08T02:45:33 Z amunduzbaev Peru (RMI20_peru) C++17
100 / 100
438 ms 33452 KB
#include "bits/stdc++.h"
using namespace std;
#include "peru.h"
#ifndef EVAL
#include "grader.cpp"
#endif
 
#define ar array
#define int long long
#define i32 int32_t
const int N = 25e5 + 5;
const int mod = 1e9 + 7;
const int P = 23;
int dp[N];
 
i32 solve(i32 n, i32 k, i32* a){
	deque<i32> ss;
	multiset<int> mm;
	i32 res = 0;
	for(int i=0;i<n;i++){
		while(!ss.empty() && ss.front() <= i - k){
			int j = ss.front(); ss.pop_front();
			if(!ss.empty()){
				mm.erase(mm.find(dp[j] + a[ss.front()]));
			}
		}
		while(!ss.empty() && a[ss.back()] <= a[i]){
			int j = ss.back(); ss.pop_back();
			if(!ss.empty()){
				mm.erase(mm.find(dp[ss.back()] + a[j]));
			}
		}
		
		dp[i] = 1e18;
		if(!ss.empty()) mm.insert(dp[ss.back()] + a[i]);
		ss.push_back(i);
		if(!mm.empty()) dp[i] = *mm.begin();
		assert(!ss.empty());
		dp[i] = min(dp[i], (i < k ? 0ll : dp[i-k]) + a[ss.front()]);
		res = (res * 1ll * P + dp[i]) % mod;
	}
	
	//~ cout<<"\n";
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 59 ms 5160 KB Output is correct
16 Correct 68 ms 5084 KB Output is correct
17 Correct 57 ms 5076 KB Output is correct
18 Correct 39 ms 5072 KB Output is correct
19 Correct 38 ms 5032 KB Output is correct
20 Correct 50 ms 5076 KB Output is correct
21 Correct 59 ms 5068 KB Output is correct
22 Correct 60 ms 5120 KB Output is correct
23 Correct 61 ms 5196 KB Output is correct
24 Correct 59 ms 5156 KB Output is correct
25 Correct 57 ms 5072 KB Output is correct
26 Correct 56 ms 5100 KB Output is correct
27 Correct 57 ms 5180 KB Output is correct
28 Correct 58 ms 5168 KB Output is correct
29 Correct 54 ms 5324 KB Output is correct
30 Correct 55 ms 5128 KB Output is correct
31 Correct 62 ms 5064 KB Output is correct
32 Correct 59 ms 5180 KB Output is correct
33 Correct 76 ms 5092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 5160 KB Output is correct
2 Correct 68 ms 5084 KB Output is correct
3 Correct 57 ms 5076 KB Output is correct
4 Correct 39 ms 5072 KB Output is correct
5 Correct 38 ms 5032 KB Output is correct
6 Correct 50 ms 5076 KB Output is correct
7 Correct 59 ms 5068 KB Output is correct
8 Correct 60 ms 5120 KB Output is correct
9 Correct 61 ms 5196 KB Output is correct
10 Correct 59 ms 5156 KB Output is correct
11 Correct 57 ms 5072 KB Output is correct
12 Correct 56 ms 5100 KB Output is correct
13 Correct 57 ms 5180 KB Output is correct
14 Correct 58 ms 5168 KB Output is correct
15 Correct 54 ms 5324 KB Output is correct
16 Correct 55 ms 5128 KB Output is correct
17 Correct 62 ms 5064 KB Output is correct
18 Correct 59 ms 5180 KB Output is correct
19 Correct 76 ms 5092 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 390 ms 29772 KB Output is correct
35 Correct 385 ms 30084 KB Output is correct
36 Correct 409 ms 30064 KB Output is correct
37 Correct 381 ms 29968 KB Output is correct
38 Correct 412 ms 30104 KB Output is correct
39 Correct 394 ms 30156 KB Output is correct
40 Correct 402 ms 30080 KB Output is correct
41 Correct 414 ms 29900 KB Output is correct
42 Correct 412 ms 30196 KB Output is correct
43 Correct 166 ms 12456 KB Output is correct
44 Correct 138 ms 18012 KB Output is correct
45 Correct 144 ms 18028 KB Output is correct
46 Correct 157 ms 17944 KB Output is correct
47 Correct 385 ms 30180 KB Output is correct
48 Correct 394 ms 30276 KB Output is correct
49 Correct 423 ms 30684 KB Output is correct
50 Correct 385 ms 31772 KB Output is correct
51 Correct 438 ms 31200 KB Output is correct
52 Correct 401 ms 33452 KB Output is correct
53 Correct 401 ms 32100 KB Output is correct
54 Correct 398 ms 30084 KB Output is correct
55 Correct 403 ms 29896 KB Output is correct
56 Correct 351 ms 29908 KB Output is correct
57 Correct 375 ms 29892 KB Output is correct
58 Correct 366 ms 29984 KB Output is correct
59 Correct 376 ms 30056 KB Output is correct
60 Correct 377 ms 29980 KB Output is correct
61 Correct 437 ms 30284 KB Output is correct
62 Correct 421 ms 30276 KB Output is correct
63 Correct 407 ms 30236 KB Output is correct