Submission #200190

# Submission time Handle Problem Language Result Execution time Memory
200190 2020-02-05T16:08:16 Z wilwxk Safety (NOI18_safety) C++14
4 / 100
1532 ms 1052 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, int r) {
	if(id > MAXN) return;
	// printf("upd %lld %d %d %d\n", val, id, l, r);
	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++) {
		int l = -x; int r = x;
		for(int j = 0; j <= min(x, MAXN); j++) update(dp[i-1][j], j, l, r);

		for(int j = 0; j < MAXN; j++) {
			while(r <MAXN && j+x > r) l++, r++, update(dp[i-1][r], r, l, r);
			ll cost = abs(j-v[i]);
			cost += query();
			// printf("%d %d >> %lld\n", i, j, cost);
			dp[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:24: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:25: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]);
                              ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Runtime error 1532 ms 1052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 6 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 8 ms 380 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Runtime error 1532 ms 1052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Runtime error 1532 ms 1052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Runtime error 1532 ms 1052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Runtime error 1532 ms 1052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 632 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Runtime error 1532 ms 1052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -