답안 #659922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659922 2022-11-19T17:32:49 Z mgl_diamond Rabbit Carrot (LMIO19_triusis) C++14
100 / 100
68 ms 11152 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using db =  double;

#define conqueror_of_uraqt int main()
#define xuong cout << "\n"
#define debug(x) cout << #x << ": " << x << endl
#define rep(i,be,en) for(int i = (be); i<=(en); ++i)
#define fod(i,be,en) for(int i = (be); i>=(en); --i)
#define each(x, a)   for(auto &x: a)
#define x first
#define y second
#define vec vector
#define endl "\n"
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define uni(a) ((a).erase(unique(all(a)),(a).end()))
#define C make_pair
#define file "input"

const int mod = 1e9+7;
template<class T> bool ckmax(T &a, T b) {if (a<b) return a=b,1; return 0;}
template<class T> bool ckmin(T &a, T b) {if (a>b) return a=b,1; return 0;}
int add(int a, int b) { a+=b; if (a>=mod) a-=mod; return a; }
int neg(int a, int b) { a-=b; if (a<0) a+=mod; return a; }
int mul(int a, int b) { return (1LL*a*b) % mod; }

const db eps = 0.0000000001;
const int M[2] = {(int)1e9+9277, (int)1e9+5277}, INF = 1e9+9, mxN = 2e5+5;

int n, m, a[mxN], dp[mxN];

map<int, int> mp;
void ins(int v1, int v2) {
	auto it = mp.lower_bound(v1);
	if (it!=mp.end() && it->y <= v2) return;
	it = mp.insert(it, C(v1, v2)); it->y = v2;
	while (it!=mp.begin() && prev(it)->y >= v2) mp.erase(prev(it));
}

int query(int x) {
	auto it = mp.lower_bound(x);
	if (it == mp.end()) return INF;
	return it->y;
}

void work() {
	cin >> n >> m;
	for(int i=1; i<=n; ++i) {
		cin >> a[i];
	}
	
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;

	int delta_m = 0, delta_j = 0;
	for(int i=1; i<=n+1; ++i) {
		delta_m += m; delta_j += 1;
		ins(a[i-1] - delta_m, dp[i-1] - delta_j);
		ckmin(dp[i], query(a[i] - delta_m - m) + delta_j);
	}

	cout << dp[n+1];
}

conqueror_of_uraqt {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	if (fopen(file".inp", "r")) {
		freopen(file".inp", "r", stdin);
		freopen(file".out", "w", stdout);
	}
	work();
	return 0;
}

Compilation message

triusis.cpp: In function 'int main()':
triusis.cpp:74:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   freopen(file".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:75:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   freopen(file".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 2 ms 1108 KB Output is correct
23 Correct 2 ms 1236 KB Output is correct
24 Correct 2 ms 1236 KB Output is correct
25 Correct 2 ms 1236 KB Output is correct
26 Correct 2 ms 1236 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 1 ms 1364 KB Output is correct
30 Correct 2 ms 1236 KB Output is correct
31 Correct 2 ms 1236 KB Output is correct
32 Correct 2 ms 1236 KB Output is correct
33 Correct 1 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 2 ms 1108 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 2 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 1 ms 980 KB Output is correct
25 Correct 1 ms 980 KB Output is correct
26 Correct 1 ms 980 KB Output is correct
27 Correct 1 ms 980 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 1 ms 980 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 980 KB Output is correct
33 Correct 1 ms 980 KB Output is correct
34 Correct 2 ms 1108 KB Output is correct
35 Correct 2 ms 1108 KB Output is correct
36 Correct 2 ms 1236 KB Output is correct
37 Correct 2 ms 1236 KB Output is correct
38 Correct 1 ms 1108 KB Output is correct
39 Correct 1 ms 1108 KB Output is correct
40 Correct 2 ms 1236 KB Output is correct
41 Correct 1 ms 1108 KB Output is correct
42 Correct 2 ms 1236 KB Output is correct
43 Correct 2 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1108 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 2 ms 1108 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1236 KB Output is correct
19 Correct 2 ms 1236 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 2 ms 1236 KB Output is correct
25 Correct 2 ms 1236 KB Output is correct
26 Correct 2 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 980 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 1 ms 980 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 1 ms 980 KB Output is correct
33 Correct 1 ms 1108 KB Output is correct
34 Correct 1 ms 980 KB Output is correct
35 Correct 1 ms 980 KB Output is correct
36 Correct 1 ms 980 KB Output is correct
37 Correct 1 ms 980 KB Output is correct
38 Correct 1 ms 980 KB Output is correct
39 Correct 1 ms 980 KB Output is correct
40 Correct 1 ms 980 KB Output is correct
41 Correct 1 ms 980 KB Output is correct
42 Correct 1 ms 980 KB Output is correct
43 Correct 1 ms 980 KB Output is correct
44 Correct 66 ms 11152 KB Output is correct
45 Correct 52 ms 1904 KB Output is correct
46 Correct 52 ms 1936 KB Output is correct
47 Correct 51 ms 1896 KB Output is correct
48 Correct 50 ms 9604 KB Output is correct
49 Correct 68 ms 10940 KB Output is correct
50 Correct 26 ms 1828 KB Output is correct
51 Correct 26 ms 1868 KB Output is correct
52 Correct 51 ms 6584 KB Output is correct
53 Correct 22 ms 1876 KB Output is correct
54 Correct 52 ms 8620 KB Output is correct
55 Correct 55 ms 8652 KB Output is correct