답안 #703226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703226 2023-02-26T15:40:38 Z ld_minh4354 Group Photo (JOI21_ho_t3) C++17
100 / 100
3527 ms 1180 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"



signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//	freopen("input.000","r",stdin);
//	freopen("output.000","w",stdout);
//	srand((unsigned)time(NULL));
//	rand()
	
	int n,i,j,k,a[5005],dp[5005],b[5005],m,cost,pos[5005];
	ordered_set s;
	
	cin>>n;
	for (i=1;i<n+1;i++) cin>>a[i];
	
	dp[n]=dp[n+1]=0;
	for (i=n-1;i>0;i--)
	{
		dp[i]=1e12;
		while (s.begin()!=s.end()) s.erase(s.begin());
		
		m=0;
		for (j=1;j<n+1;j++) if (a[j]>=i)
		{
			m++;b[m]=a[j];
		}
		
		for (j=1;j<m+1;j++) pos[b[j]]=j;
		
		cost=0;
		for (j=i;j<n+1;j++)
		{
			cost += pos[j] - 1 - s.order_of_key(-pos[j]);
			s.insert(-pos[j]);
			
			dp[i]=min(dp[i], cost + dp[j+1]);
			
//			cout<<i<<" "<<j<<" :"<< cost+dp[j+1]<<"\n";
		}
	}
	
	cout<<dp[1];
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:12: warning: unused variable 'k' [-Wunused-variable]
   25 |  int n,i,j,k,a[5005],dp[5005],b[5005],m,cost,pos[5005];
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 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 0 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 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 0 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 480 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 468 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 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 0 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 480 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 468 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 68 ms 488 KB Output is correct
32 Correct 69 ms 468 KB Output is correct
33 Correct 68 ms 624 KB Output is correct
34 Correct 71 ms 512 KB Output is correct
35 Correct 71 ms 500 KB Output is correct
36 Correct 68 ms 500 KB Output is correct
37 Correct 70 ms 500 KB Output is correct
38 Correct 69 ms 468 KB Output is correct
39 Correct 68 ms 496 KB Output is correct
40 Correct 68 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 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 0 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 480 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 468 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 68 ms 488 KB Output is correct
32 Correct 69 ms 468 KB Output is correct
33 Correct 68 ms 624 KB Output is correct
34 Correct 71 ms 512 KB Output is correct
35 Correct 71 ms 500 KB Output is correct
36 Correct 68 ms 500 KB Output is correct
37 Correct 70 ms 500 KB Output is correct
38 Correct 69 ms 468 KB Output is correct
39 Correct 68 ms 496 KB Output is correct
40 Correct 68 ms 468 KB Output is correct
41 Correct 3509 ms 1092 KB Output is correct
42 Correct 3494 ms 904 KB Output is correct
43 Correct 3459 ms 952 KB Output is correct
44 Correct 3464 ms 1092 KB Output is correct
45 Correct 3449 ms 944 KB Output is correct
46 Correct 3460 ms 1020 KB Output is correct
47 Correct 3468 ms 1040 KB Output is correct
48 Correct 3451 ms 1084 KB Output is correct
49 Correct 3527 ms 1088 KB Output is correct
50 Correct 3462 ms 1008 KB Output is correct
51 Correct 3483 ms 996 KB Output is correct
52 Correct 3485 ms 1064 KB Output is correct
53 Correct 3454 ms 1180 KB Output is correct
54 Correct 3468 ms 1132 KB Output is correct
55 Correct 3466 ms 1076 KB Output is correct