답안 #200193

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200193 2020-02-05T16:15:58 Z wilwxk Safety (NOI18_safety) C++14
13 / 100
47 ms 19960 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 5e3+5;
int v[MAXN];
ll dp[MAXN][MAXN];
deque<pair<ll, int> > dq;
int n, x;

void update(ll val, int id, int l) {
	if(id >= MAXN) return;
	while(dq.size() && dq.back().second < l) dq.pop_back();
	while(dq.size() && dq.front().first >= val) dq.pop_front();
	dq.push_front({val, id});
}

ll query() {
	return dq.back().first;
}

int main() {
	scanf("%d %d", &n, &x);
	for(int i = 1; i <= n; i++) scanf("%d", &v[i]);

	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < min(x, MAXN); j++) update(dp[i-1][j], j, -1);

		for(int j = 0; j < MAXN; j++) {
			update(dp[i-1][j+x], j+x, j-x);

			ll cost = abs(j-v[i]);
			cost += query();
			dp[i][j] = cost;
			// printf("%d %d >> %lld\n", i, j, cost);
		}
		while(dq.size()) dq.pop_back();
	}

	ll ans = 1e18;
	for(int i = 0; i < MAXN; i++) ans = min(ans, dp[n][i]);
	printf("%lld\n", ans);
}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~
safety.cpp:24:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", &v[i]);
                              ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 6 ms 760 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 888 KB Output is correct
2 Correct 6 ms 888 KB Output is correct
3 Correct 6 ms 888 KB Output is correct
4 Correct 6 ms 888 KB Output is correct
5 Correct 7 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6 ms 376 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 6 ms 760 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 6 ms 888 KB Output is correct
11 Correct 6 ms 888 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Correct 47 ms 19960 KB Output is correct
14 Correct 44 ms 19228 KB Output is correct
15 Correct 45 ms 19448 KB Output is correct
16 Correct 46 ms 19960 KB Output is correct
17 Correct 43 ms 17656 KB Output is correct
18 Correct 38 ms 14712 KB Output is correct
19 Correct 47 ms 19064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 6 ms 760 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 6 ms 888 KB Output is correct
11 Correct 6 ms 888 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Correct 47 ms 19960 KB Output is correct
14 Correct 44 ms 19228 KB Output is correct
15 Correct 45 ms 19448 KB Output is correct
16 Correct 46 ms 19960 KB Output is correct
17 Correct 43 ms 17656 KB Output is correct
18 Correct 38 ms 14712 KB Output is correct
19 Correct 47 ms 19064 KB Output is correct
20 Incorrect 47 ms 18680 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 6 ms 760 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 6 ms 888 KB Output is correct
11 Correct 6 ms 888 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Correct 47 ms 19960 KB Output is correct
14 Correct 44 ms 19228 KB Output is correct
15 Correct 45 ms 19448 KB Output is correct
16 Correct 46 ms 19960 KB Output is correct
17 Correct 43 ms 17656 KB Output is correct
18 Correct 38 ms 14712 KB Output is correct
19 Correct 47 ms 19064 KB Output is correct
20 Incorrect 47 ms 18680 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 6 ms 760 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 6 ms 888 KB Output is correct
11 Correct 6 ms 888 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Incorrect 5 ms 632 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 6 ms 760 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 6 ms 888 KB Output is correct
11 Correct 6 ms 888 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Incorrect 5 ms 632 KB Output isn't correct
14 Halted 0 ms 0 KB -