답안 #643343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643343 2022-09-21T18:55:43 Z Augustyn Group Photo (JOI21_ho_t3) C++14
100 / 100
395 ms 196676 KB
#include<bits/stdc++.h>
using namespace std;
int n,h[5001],gdzie[5001];
int dp[5011],ilewiek[5011][5011],ilemn[5011][5011];
int czynap(int a,int b)
{
	if(gdzie[a]<gdzie[b])
		return 1;
	return 0;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&h[i]);
		gdzie[h[i]]=i;
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=n;j>i;--j)
			ilewiek[i][j]=ilewiek[i][j+1]+czynap(j,i);
		for(int j=i;j>0;--j)
			ilemn[i][j]=ilemn[i][j+1]+czynap(j,i);
		ilemn[i][0]+=ilemn[i][1];
		for(int j=i;j>=0;--j)
			ilewiek[i][j]+=ilewiek[i][j+1];
	}
	for(int i=n;i>=0;--i)
	{
		for(int j=n;j>=0;--j)
			ilewiek[i][j]+=ilewiek[i+1][j];
		for(int j=n;j>=0;--j)
			ilemn[i][j]+=ilemn[i+1][j];
	}
	for(int i=1;i<=n;++i)
	{
		dp[i]=INT_MAX; 
		for(int j=1;j<=i;++j)
		{
			dp[i]=min(dp[i],dp[j-1]+ilewiek[j][i+1]-ilewiek[i+1][i+1]+ilemn[j][j]-ilemn[i+1][j]);
		}
	}
	printf("%d",dp[n]);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
Main.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%d",&h[i]);
      |   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 276 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 276 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 432 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 0 ms 432 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 276 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 432 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 0 ms 432 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 2 ms 2132 KB Output is correct
22 Correct 2 ms 2132 KB Output is correct
23 Correct 2 ms 2132 KB Output is correct
24 Correct 2 ms 2260 KB Output is correct
25 Correct 1 ms 2260 KB Output is correct
26 Correct 2 ms 2260 KB Output is correct
27 Correct 2 ms 2260 KB Output is correct
28 Correct 2 ms 2132 KB Output is correct
29 Correct 2 ms 2136 KB Output is correct
30 Correct 2 ms 2228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 276 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 432 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 0 ms 432 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 2 ms 2132 KB Output is correct
22 Correct 2 ms 2132 KB Output is correct
23 Correct 2 ms 2132 KB Output is correct
24 Correct 2 ms 2260 KB Output is correct
25 Correct 1 ms 2260 KB Output is correct
26 Correct 2 ms 2260 KB Output is correct
27 Correct 2 ms 2260 KB Output is correct
28 Correct 2 ms 2132 KB Output is correct
29 Correct 2 ms 2136 KB Output is correct
30 Correct 2 ms 2228 KB Output is correct
31 Correct 12 ms 11708 KB Output is correct
32 Correct 11 ms 11732 KB Output is correct
33 Correct 12 ms 11676 KB Output is correct
34 Correct 12 ms 11772 KB Output is correct
35 Correct 12 ms 11756 KB Output is correct
36 Correct 12 ms 11696 KB Output is correct
37 Correct 11 ms 11764 KB Output is correct
38 Correct 11 ms 11772 KB Output is correct
39 Correct 11 ms 11700 KB Output is correct
40 Correct 11 ms 11732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 276 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 0 ms 308 KB Output is correct
11 Correct 1 ms 432 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 0 ms 432 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 2 ms 2132 KB Output is correct
22 Correct 2 ms 2132 KB Output is correct
23 Correct 2 ms 2132 KB Output is correct
24 Correct 2 ms 2260 KB Output is correct
25 Correct 1 ms 2260 KB Output is correct
26 Correct 2 ms 2260 KB Output is correct
27 Correct 2 ms 2260 KB Output is correct
28 Correct 2 ms 2132 KB Output is correct
29 Correct 2 ms 2136 KB Output is correct
30 Correct 2 ms 2228 KB Output is correct
31 Correct 12 ms 11708 KB Output is correct
32 Correct 11 ms 11732 KB Output is correct
33 Correct 12 ms 11676 KB Output is correct
34 Correct 12 ms 11772 KB Output is correct
35 Correct 12 ms 11756 KB Output is correct
36 Correct 12 ms 11696 KB Output is correct
37 Correct 11 ms 11764 KB Output is correct
38 Correct 11 ms 11772 KB Output is correct
39 Correct 11 ms 11700 KB Output is correct
40 Correct 11 ms 11732 KB Output is correct
41 Correct 386 ms 196412 KB Output is correct
42 Correct 389 ms 196388 KB Output is correct
43 Correct 387 ms 196428 KB Output is correct
44 Correct 389 ms 196596 KB Output is correct
45 Correct 390 ms 196500 KB Output is correct
46 Correct 394 ms 196568 KB Output is correct
47 Correct 391 ms 196604 KB Output is correct
48 Correct 391 ms 196636 KB Output is correct
49 Correct 395 ms 196676 KB Output is correct
50 Correct 389 ms 196428 KB Output is correct
51 Correct 389 ms 196508 KB Output is correct
52 Correct 387 ms 196536 KB Output is correct
53 Correct 383 ms 196544 KB Output is correct
54 Correct 384 ms 196544 KB Output is correct
55 Correct 389 ms 196604 KB Output is correct