답안 #963699

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

#define ll long long
ll ab(ll n) { return n > 0 ? n : -n; }
long long func(int n, int h, vector<int> s) {
	vector<ll> dp(501,0);

	for (int i = 0; i < n; i++) {
		vector<ll> ndp(501);
		for (int j = 0; j <= 500; j++) {
			ndp[j] = ab(j - s[i]);
			ll mn = 1e18;
			for (int k = max(0, j - h); k <= min(500, j + h); k++) mn = min(mn, dp[k]);
			ndp[j] += mn;
		}
		dp = ndp;
	}

	ll mn = 1e18;
	for (int i = 0; i <= 500; 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:36:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   36 |  printf("%d\n", ans);
      |          ~^     ~~~
      |           |     |
      |           int   long long int
      |          %lld
safety.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d%d", &N, &H);
      |  ~~~~~^~~~~~~~~~~~~~~~
safety.cpp:32:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  for (int i = 0; i < N; i++) scanf("%d", &S[i]);
      |                              ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 428 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 174 ms 2216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 428 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 114 ms 348 KB Output is correct
16 Correct 62 ms 348 KB Output is correct
17 Correct 99 ms 408 KB Output is correct
18 Correct 62 ms 344 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 428 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 114 ms 348 KB Output is correct
16 Correct 62 ms 348 KB Output is correct
17 Correct 99 ms 408 KB Output is correct
18 Correct 62 ms 344 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Incorrect 107 ms 400 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 428 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 114 ms 348 KB Output is correct
16 Correct 62 ms 348 KB Output is correct
17 Correct 99 ms 408 KB Output is correct
18 Correct 62 ms 344 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Incorrect 107 ms 400 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 428 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 428 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -