답안 #397694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
397694 2021-05-02T21:21:29 Z ChrisT Group Photo (JOI21_ho_t3) C++17
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
const int MN = 5e3 + 5;
int dp[MN], f[MN][MN], a[MN], stopAt[MN];
int main () {
	int n; scanf ("%d",&n);
	for (int i = 1; i <= n; i++) scanf ("%d",&a[i]);
	for (int i = 1; i <= n; i++) {
		for (int j = i+1; j <= n; j++) {
			if (a[i] < a[j]) {
				f[1][a[j]]++; f[a[i]+1][a[j]]--;
			} else {
				f[a[j]+1][1]++; f[a[i]+1][1]--;
			}
		}
	}
	for (int i = 1; i <= n; i++) 
		for (int j = 1; j <= n; j++) 
			f[i][j] += f[i-1][j] + f[i][j-1] - f[i-1][j-1];
	for (int i = 1; i <= n; i++) {
		dp[i] = 1e9;
		for (int j = i; j >= 1; j--) dp[i] = min(dp[i],dp[j-1]+f[j][i]);
	}
	printf ("%d\n",dp[n]);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:6:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 |  int n; scanf ("%d",&n);
      |         ~~~~~~^~~~~~~~~
Main.cpp:7:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |  for (int i = 1; i <= n; i++) scanf ("%d",&a[i]);
      |                               ~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Halted 0 ms 0 KB -