답안 #478902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478902 2021-10-09T04:39:13 Z arwaeystoamneg Group Photo (JOI21_ho_t3) Java 11
64 / 100
5000 ms 15828 KB
import java.util.*;
import java.io.*;
class segment_tree// "segment tree"
{
	int n;
	int[]a;
	segment_tree(int n)
	{
		this.n = n;
		a = new int[n];
	}
	void update(int i,int j)
	{
		a[i] = j;
	}
	int query(int i,int j)
	{
		int ans= 0;
		for(int k = i;k<j + 1;k++)ans += a[k];
		return ans;
	}
}
public class Main
{

	public static void main(String[]args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a= new int[n];
		for(int i = 0;i<n;i++) {a[i] = sc.nextInt();a[i]--;}
		int[]dp = new int[n + 1];
		for(int i= 0;i<n+1;i++)dp[i] = 1000000000;
		dp[n] = 0;
		for(int i= n;i>=0;i--)
		{
			int val = dp[i];
			ArrayList<Integer>b = new ArrayList<Integer>();
			for(int y:a)if(y<i)b.add(y);
			int[]idx = new int[i];
			for(int j = 0;j<i;j++)idx[b.get(j)] = j;
			segment_tree sum = new segment_tree(i);
			for(int j= i -1;j>=0;j--)
			{
				val += i - idx[j] - 1;
				val -=sum.query(0,idx[j]);
				sum.update(idx[j],1);
				dp[j] = Math.min(dp[j],val);
			}
			
		}
		System.out.println(dp[0]);
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 10740 KB Output is correct
2 Correct 115 ms 9928 KB Output is correct
3 Correct 109 ms 10112 KB Output is correct
4 Correct 117 ms 10220 KB Output is correct
5 Correct 129 ms 10100 KB Output is correct
6 Correct 109 ms 10216 KB Output is correct
7 Correct 113 ms 10048 KB Output is correct
8 Correct 117 ms 10196 KB Output is correct
9 Correct 112 ms 10340 KB Output is correct
10 Correct 113 ms 10092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 10740 KB Output is correct
2 Correct 115 ms 9928 KB Output is correct
3 Correct 109 ms 10112 KB Output is correct
4 Correct 117 ms 10220 KB Output is correct
5 Correct 129 ms 10100 KB Output is correct
6 Correct 109 ms 10216 KB Output is correct
7 Correct 113 ms 10048 KB Output is correct
8 Correct 117 ms 10196 KB Output is correct
9 Correct 112 ms 10340 KB Output is correct
10 Correct 113 ms 10092 KB Output is correct
11 Correct 121 ms 10176 KB Output is correct
12 Correct 112 ms 10412 KB Output is correct
13 Correct 110 ms 10272 KB Output is correct
14 Correct 110 ms 10204 KB Output is correct
15 Correct 111 ms 10056 KB Output is correct
16 Correct 116 ms 10036 KB Output is correct
17 Correct 119 ms 10052 KB Output is correct
18 Correct 109 ms 10068 KB Output is correct
19 Correct 115 ms 10384 KB Output is correct
20 Correct 114 ms 10060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 10740 KB Output is correct
2 Correct 115 ms 9928 KB Output is correct
3 Correct 109 ms 10112 KB Output is correct
4 Correct 117 ms 10220 KB Output is correct
5 Correct 129 ms 10100 KB Output is correct
6 Correct 109 ms 10216 KB Output is correct
7 Correct 113 ms 10048 KB Output is correct
8 Correct 117 ms 10196 KB Output is correct
9 Correct 112 ms 10340 KB Output is correct
10 Correct 113 ms 10092 KB Output is correct
11 Correct 121 ms 10176 KB Output is correct
12 Correct 112 ms 10412 KB Output is correct
13 Correct 110 ms 10272 KB Output is correct
14 Correct 110 ms 10204 KB Output is correct
15 Correct 111 ms 10056 KB Output is correct
16 Correct 116 ms 10036 KB Output is correct
17 Correct 119 ms 10052 KB Output is correct
18 Correct 109 ms 10068 KB Output is correct
19 Correct 115 ms 10384 KB Output is correct
20 Correct 114 ms 10060 KB Output is correct
21 Correct 218 ms 13360 KB Output is correct
22 Correct 203 ms 13276 KB Output is correct
23 Correct 197 ms 13588 KB Output is correct
24 Correct 220 ms 13392 KB Output is correct
25 Correct 206 ms 13556 KB Output is correct
26 Correct 197 ms 13664 KB Output is correct
27 Correct 207 ms 13440 KB Output is correct
28 Correct 218 ms 13436 KB Output is correct
29 Correct 206 ms 13276 KB Output is correct
30 Correct 209 ms 13400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 10740 KB Output is correct
2 Correct 115 ms 9928 KB Output is correct
3 Correct 109 ms 10112 KB Output is correct
4 Correct 117 ms 10220 KB Output is correct
5 Correct 129 ms 10100 KB Output is correct
6 Correct 109 ms 10216 KB Output is correct
7 Correct 113 ms 10048 KB Output is correct
8 Correct 117 ms 10196 KB Output is correct
9 Correct 112 ms 10340 KB Output is correct
10 Correct 113 ms 10092 KB Output is correct
11 Correct 121 ms 10176 KB Output is correct
12 Correct 112 ms 10412 KB Output is correct
13 Correct 110 ms 10272 KB Output is correct
14 Correct 110 ms 10204 KB Output is correct
15 Correct 111 ms 10056 KB Output is correct
16 Correct 116 ms 10036 KB Output is correct
17 Correct 119 ms 10052 KB Output is correct
18 Correct 109 ms 10068 KB Output is correct
19 Correct 115 ms 10384 KB Output is correct
20 Correct 114 ms 10060 KB Output is correct
21 Correct 218 ms 13360 KB Output is correct
22 Correct 203 ms 13276 KB Output is correct
23 Correct 197 ms 13588 KB Output is correct
24 Correct 220 ms 13392 KB Output is correct
25 Correct 206 ms 13556 KB Output is correct
26 Correct 197 ms 13664 KB Output is correct
27 Correct 207 ms 13440 KB Output is correct
28 Correct 218 ms 13436 KB Output is correct
29 Correct 206 ms 13276 KB Output is correct
30 Correct 209 ms 13400 KB Output is correct
31 Correct 297 ms 15144 KB Output is correct
32 Correct 311 ms 14992 KB Output is correct
33 Correct 302 ms 14744 KB Output is correct
34 Correct 308 ms 15000 KB Output is correct
35 Correct 316 ms 14864 KB Output is correct
36 Correct 304 ms 14992 KB Output is correct
37 Correct 309 ms 14648 KB Output is correct
38 Correct 319 ms 14772 KB Output is correct
39 Correct 306 ms 14808 KB Output is correct
40 Correct 328 ms 14912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 10740 KB Output is correct
2 Correct 115 ms 9928 KB Output is correct
3 Correct 109 ms 10112 KB Output is correct
4 Correct 117 ms 10220 KB Output is correct
5 Correct 129 ms 10100 KB Output is correct
6 Correct 109 ms 10216 KB Output is correct
7 Correct 113 ms 10048 KB Output is correct
8 Correct 117 ms 10196 KB Output is correct
9 Correct 112 ms 10340 KB Output is correct
10 Correct 113 ms 10092 KB Output is correct
11 Correct 121 ms 10176 KB Output is correct
12 Correct 112 ms 10412 KB Output is correct
13 Correct 110 ms 10272 KB Output is correct
14 Correct 110 ms 10204 KB Output is correct
15 Correct 111 ms 10056 KB Output is correct
16 Correct 116 ms 10036 KB Output is correct
17 Correct 119 ms 10052 KB Output is correct
18 Correct 109 ms 10068 KB Output is correct
19 Correct 115 ms 10384 KB Output is correct
20 Correct 114 ms 10060 KB Output is correct
21 Correct 218 ms 13360 KB Output is correct
22 Correct 203 ms 13276 KB Output is correct
23 Correct 197 ms 13588 KB Output is correct
24 Correct 220 ms 13392 KB Output is correct
25 Correct 206 ms 13556 KB Output is correct
26 Correct 197 ms 13664 KB Output is correct
27 Correct 207 ms 13440 KB Output is correct
28 Correct 218 ms 13436 KB Output is correct
29 Correct 206 ms 13276 KB Output is correct
30 Correct 209 ms 13400 KB Output is correct
31 Correct 297 ms 15144 KB Output is correct
32 Correct 311 ms 14992 KB Output is correct
33 Correct 302 ms 14744 KB Output is correct
34 Correct 308 ms 15000 KB Output is correct
35 Correct 316 ms 14864 KB Output is correct
36 Correct 304 ms 14992 KB Output is correct
37 Correct 309 ms 14648 KB Output is correct
38 Correct 319 ms 14772 KB Output is correct
39 Correct 306 ms 14808 KB Output is correct
40 Correct 328 ms 14912 KB Output is correct
41 Execution timed out 5018 ms 15828 KB Time limit exceeded
42 Halted 0 ms 0 KB -