답안 #963842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963842 2024-04-15T19:34:22 Z guechotjrhh Safety (NOI18_safety) C++14
0 / 100
20 ms 2140 KB
#include<stdio.h>
#include<vector>
#pragma warning (disable:4996)
using namespace std;

#include<algorithm>
#define ll long long
ll ab(ll n) { return n > 0 ? n : -n; }
int sz = 5001;
long long func(int n, int h, vector<int> s) {
	sort(s.begin(), s.end());
	ll r = 0;
	for (int i = 0; i < n; i++) r += ab(s[i] - s[n / 2]);
	return r;

	vector<ll> dp(sz,0);

	int mi = 0;

	for (int i = 0; i < n; i++) {
		vector<ll> ndp(sz);
		for (int j = 0; j < sz; j++) {
			ndp[j] = ab(j - s[i]);
			int d = max(0, j - h), u = min(sz - 1, j + h);
			if (d <= mi && u >= mi) ndp[j] += dp[mi];
			if (d > mi) ndp[j] += dp[d];
			if (u < mi) ndp[j] += dp[u];
			//ll mn = 1e18;
			//for (int k = max(0, j - h); k <= min(sz-1, j + h); k++) mn = min(mn, dp[k]);
			//ndp[j] += mn;
		}
		//for (int j : dp) printf("%d ", j); printf("\n");
		dp = ndp;

		mi = 0;
		for (int i = 0; i < sz; i++) if (dp[i] < dp[mi]) mi = i;
	}

	ll mn = 1e18;
	for (int i = 0; i < sz; i++) mn = min(mn, dp[i]);

	return mn;
}

int main() {
	int N, H;
	scanf("%d%d", &N, &H);
	vector<int> S(N);
	for (int i = 0; i < N; i++) scanf("%d", &S[i]);

	long long ans = func(N, H, move(S));

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

Compilation message

safety.cpp:3: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
    3 | #pragma warning (disable:4996)
      | 
safety.cpp: In function 'int main()':
safety.cpp:53:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   53 |  printf("%d\n", ans);
      |          ~^     ~~~
      |           |     |
      |           int   long long int
      |          %lld
safety.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d%d", &N, &H);
      |  ~~~~~^~~~~~~~~~~~~~~~
safety.cpp:49:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  for (int i = 0; i < N; i++) scanf("%d", &S[i]);
      |                              ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 2140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 416 KB Output isn't correct
2 Halted 0 ms 0 KB -