Submission #200202

# Submission time Handle Problem Language Result Execution time Memory
200202 2020-02-05T16:45:15 Z wilwxk Safety (NOI18_safety) C++14
13 / 100
2000 ms 376 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 20;
int v[MAXN], aux[MAXN], vv[MAXN];
ll ans = 1e18;
int n, x;

void brute(int id) {
	if(id == n) {
		for(int i = 1; i <= n; i++) {
			vv[i] = v[i];
			for(int j = i-1; j >= 1; j--) vv[j] = vv[j+1]+aux[j];
			for(int j = i+1; j <= n; j++) vv[j] = vv[j-1]+aux[j-1];

			ll val = 0;
			for(int i = 1; i <= n; i++) val += abs(vv[i]-v[i]);
			ans = min(ans, val);
		}
		return;
	}
	for(int k = -x; k <= x; k++) {
		aux[id] = k;
		brute(id+1);
	}
}

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

	brute(1);

	printf("%lld\n", ans);
}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:30: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:31: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 Execution timed out 2076 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 826 ms 376 KB Output is correct
3 Correct 224 ms 256 KB Output is correct
4 Correct 818 ms 376 KB Output is correct
5 Correct 830 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 256 KB Output is correct
2 Correct 9 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 9 ms 376 KB Output is correct
5 Correct 9 ms 256 KB Output is correct
6 Correct 9 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6 ms 256 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -