답안 #659621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659621 2022-11-18T18:58:18 Z jcelin Peru (RMI20_peru) C++14
100 / 100
451 ms 58984 KB
//#include "peru.h"
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define matrix vector<vi>
#define matrixLL vector<vll>
#define vs vector<string>
#define vui vector<ui>
#define msi multiset<int>
#define mss multiset<string>
#define si set<int>
#define ss set<string>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int dxx[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dyy[] = {0, 0, -1, 1, -1, 1, -1, 1};
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ld pi = 3.14159265;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 25 * 1e5 + 7;
const int inf = mod;
const ll INF = 1e18;
const ll zero = ll(0);
const int logo = 20;
const int off = 1 << logo;
const int trsz = off << 1;

int add(ll a, ll b){
	return (a + b) % mod;
}

int mul(ll a, ll b){
	return (a * b) % mod;
}

ll dp[MAXN];

int solve(int n, int k, int *arr){
	deque<int> dq;
	multiset<ll> m;
	si s;
	int ret = 0;
	REP(i, n){
		while(!dq.empty() and dq.front() <= i - k){
			int j = dq.front();
			dq.PPF();
			if(!dq.empty()) m.erase(m.find(dp[j] + arr[dq.front()]));
		}
		
		while(!dq.empty() and arr[dq.back()] <= arr[i]){
			int j = dq.back();
			dq.PPB();
			if(!dq.empty()) m.erase(m.find(dp[dq.back()] + arr[j])); 
		}
		
		
		dp[i] = INF;
		if(!dq.empty()) m.insert(dp[dq.back()] + arr[i]);
		dq.PB(i);
		if(!m.empty()) dp[i] = *m.begin();
		
		if(i < k) dp[i] = min(dp[i], (ll)arr[dq.front()]);
		else dp[i] = min(dp[i], arr[dq.front()] + dp[i - k]);
		ret = add(mul(23, ret), dp[i]);
	}
	return ret;
}

/*
void solv(){
	int n, k;
	cin >> n >> k;
	vi arr; arr.clear();
	REP(i, n){
		int x;
		cin >> x;
		arr.PB(x);
	}
	
	cout << solve(n, k, arr);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--)solv();
	return 0;
}

*/
# 결과 실행 시간 메모리 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 276 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 276 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 58 ms 5116 KB Output is correct
16 Correct 56 ms 5040 KB Output is correct
17 Correct 57 ms 5132 KB Output is correct
18 Correct 38 ms 5112 KB Output is correct
19 Correct 39 ms 5000 KB Output is correct
20 Correct 38 ms 5060 KB Output is correct
21 Correct 67 ms 5084 KB Output is correct
22 Correct 61 ms 5124 KB Output is correct
23 Correct 63 ms 5224 KB Output is correct
24 Correct 58 ms 5204 KB Output is correct
25 Correct 58 ms 5148 KB Output is correct
26 Correct 57 ms 5064 KB Output is correct
27 Correct 65 ms 5076 KB Output is correct
28 Correct 62 ms 5248 KB Output is correct
29 Correct 74 ms 5312 KB Output is correct
30 Correct 62 ms 5152 KB Output is correct
31 Correct 60 ms 5136 KB Output is correct
32 Correct 61 ms 5172 KB Output is correct
33 Correct 67 ms 5224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 5116 KB Output is correct
2 Correct 56 ms 5040 KB Output is correct
3 Correct 57 ms 5132 KB Output is correct
4 Correct 38 ms 5112 KB Output is correct
5 Correct 39 ms 5000 KB Output is correct
6 Correct 38 ms 5060 KB Output is correct
7 Correct 67 ms 5084 KB Output is correct
8 Correct 61 ms 5124 KB Output is correct
9 Correct 63 ms 5224 KB Output is correct
10 Correct 58 ms 5204 KB Output is correct
11 Correct 58 ms 5148 KB Output is correct
12 Correct 57 ms 5064 KB Output is correct
13 Correct 65 ms 5076 KB Output is correct
14 Correct 62 ms 5248 KB Output is correct
15 Correct 74 ms 5312 KB Output is correct
16 Correct 62 ms 5152 KB Output is correct
17 Correct 60 ms 5136 KB Output is correct
18 Correct 61 ms 5172 KB Output is correct
19 Correct 67 ms 5224 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 276 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 399 ms 29928 KB Output is correct
35 Correct 418 ms 53700 KB Output is correct
36 Correct 399 ms 53572 KB Output is correct
37 Correct 415 ms 53456 KB Output is correct
38 Correct 411 ms 53700 KB Output is correct
39 Correct 421 ms 53816 KB Output is correct
40 Correct 428 ms 53676 KB Output is correct
41 Correct 396 ms 53552 KB Output is correct
42 Correct 415 ms 53692 KB Output is correct
43 Correct 148 ms 22020 KB Output is correct
44 Correct 159 ms 33296 KB Output is correct
45 Correct 147 ms 33356 KB Output is correct
46 Correct 156 ms 33428 KB Output is correct
47 Correct 406 ms 55720 KB Output is correct
48 Correct 424 ms 55864 KB Output is correct
49 Correct 423 ms 56280 KB Output is correct
50 Correct 390 ms 57452 KB Output is correct
51 Correct 419 ms 56868 KB Output is correct
52 Correct 415 ms 58984 KB Output is correct
53 Correct 402 ms 57636 KB Output is correct
54 Correct 412 ms 53500 KB Output is correct
55 Correct 402 ms 53508 KB Output is correct
56 Correct 402 ms 53468 KB Output is correct
57 Correct 376 ms 53544 KB Output is correct
58 Correct 385 ms 53520 KB Output is correct
59 Correct 412 ms 53720 KB Output is correct
60 Correct 393 ms 53520 KB Output is correct
61 Correct 451 ms 56016 KB Output is correct
62 Correct 446 ms 55760 KB Output is correct
63 Correct 411 ms 55616 KB Output is correct