Submission #200201

# Submission time Handle Problem Language Result Execution time Memory
200201 2020-02-05T16:44:00 Z wilwxk Safety (NOI18_safety) C++14
0 / 100
2000 ms 504 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];

			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 2096 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 798 ms 248 KB Output is correct
3 Incorrect 240 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6 ms 376 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2096 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2096 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2096 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2096 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2096 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -