제출 #200201

#제출 시각아이디문제언어결과실행 시간메모리
200201wilwxkSafety (NOI18_safety)C++14
0 / 100
2096 ms504 KiB
#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);
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...