답안 #209420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209420 2020-03-14T07:23:47 Z model_code Visiting Singapore (NOI20_visitingsingapore) Java 11
100 / 100
1849 ms 30848 KB
import java.util.Scanner;
class VisitingSingapore {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int k = input.nextInt();
    int n= input.nextInt();
    int m = input.nextInt();
    long x = input.nextInt();
    long y = input.nextInt();
    x = -x;
    y = -y;
    long ans = -x-y*m;
    long val[] = new long[k + 1]; 
    for (int i = 0; i < k; i++) {
      val[i+1] = input.nextInt();
    } 
    int arr[] = new int[n + 1];
    int arr2[] = new int[m + 1];
    for (int i = 1; i <= n; i++) {
      arr[i] = input.nextInt();
    } 
    for (int i = 1; i <= m; i++) {
      arr2[i] = input.nextInt();
    }
    long dp[][][] = new long[2][m+2][4];
    long lower = -2000000000;
    for(int i=1;i<=m;i++){
		dp[0][i][0] = lower;
		dp[0][i][1] = lower;
		dp[0][i][3] = lower;
		dp[0][i][2] = -x-y*i;
	}
	dp[0][0][0] = lower;
	dp[0][0][1] = lower;
	dp[0][0][2] = lower;
	dp[0][0][3] = 0;
	dp[1][0][0] = lower;
	dp[1][0][1] = lower;
	dp[1][0][2] = lower;
	dp[1][0][3] = 0;
    for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i%2][j][0] = Math.max(-x-y*j,Math.max(Math.max(dp[i%2][j-1][0],dp[(i-1)%2][j][0])-y,Math.max(dp[(i-1)%2][j][2],dp[i%2][j-1][1])-x-y));
			dp[i%2][j][1] = Math.max(dp[(i-1)%2][j][1]-y,dp[(i-1)%2][j][3]-x-y);
			dp[i%2][j][2] = Math.max(Math.max(dp[i%2][j-1][2]-y,dp[i%2][j-1][3]-x-y),-x-y*j);
			if(arr[i]==arr2[j]){
				dp[i%2][j][3] = (long)val[arr[i]]+Math.max(Math.max(dp[(i-1)%2][j-1][0],dp[(i-1)%2][j-1][1]),Math.max((long)dp[(i-1)%2][j-1][2],(long)dp[(i-1)%2][j-1][3]));
			}else dp[i%2][j][3] = lower;
//			cout<<i<<" "<<j<<" states: \n";
//			for(k=0;k<4;k++)cout<<dp[i][j][k]<<" "<<k/2<<k%2<<'\n';
		}
		for(int j=0;j<4;j++)ans = Math.max(ans,dp[i%2][m][j]);
	}
    System.out.println(ans);
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 12700 KB Output is correct
2 Correct 367 ms 16360 KB Output is correct
3 Correct 165 ms 12104 KB Output is correct
4 Correct 203 ms 15260 KB Output is correct
5 Correct 154 ms 12244 KB Output is correct
6 Correct 310 ms 15444 KB Output is correct
7 Correct 159 ms 12152 KB Output is correct
8 Correct 267 ms 14552 KB Output is correct
9 Correct 352 ms 16448 KB Output is correct
10 Correct 409 ms 19224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 193 ms 15228 KB Output is correct
2 Correct 151 ms 12448 KB Output is correct
3 Correct 298 ms 15872 KB Output is correct
4 Correct 155 ms 12144 KB Output is correct
5 Correct 237 ms 14232 KB Output is correct
6 Correct 313 ms 16272 KB Output is correct
7 Correct 314 ms 16696 KB Output is correct
8 Correct 335 ms 16644 KB Output is correct
9 Correct 246 ms 14244 KB Output is correct
10 Correct 405 ms 16980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 21484 KB Output is correct
2 Correct 400 ms 21164 KB Output is correct
3 Correct 689 ms 23276 KB Output is correct
4 Correct 1303 ms 28556 KB Output is correct
5 Correct 582 ms 21360 KB Output is correct
6 Correct 693 ms 21584 KB Output is correct
7 Correct 992 ms 25472 KB Output is correct
8 Correct 581 ms 23320 KB Output is correct
9 Correct 759 ms 23920 KB Output is correct
10 Correct 1303 ms 26780 KB Output is correct
11 Correct 1330 ms 26668 KB Output is correct
12 Correct 1570 ms 30332 KB Output is correct
13 Correct 1472 ms 30028 KB Output is correct
14 Correct 1413 ms 28416 KB Output is correct
15 Correct 1239 ms 25504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 21484 KB Output is correct
2 Correct 400 ms 21164 KB Output is correct
3 Correct 689 ms 23276 KB Output is correct
4 Correct 1303 ms 28556 KB Output is correct
5 Correct 582 ms 21360 KB Output is correct
6 Correct 693 ms 21584 KB Output is correct
7 Correct 992 ms 25472 KB Output is correct
8 Correct 581 ms 23320 KB Output is correct
9 Correct 759 ms 23920 KB Output is correct
10 Correct 1303 ms 26780 KB Output is correct
11 Correct 1330 ms 26668 KB Output is correct
12 Correct 1570 ms 30332 KB Output is correct
13 Correct 1472 ms 30028 KB Output is correct
14 Correct 1413 ms 28416 KB Output is correct
15 Correct 1239 ms 25504 KB Output is correct
16 Correct 821 ms 23548 KB Output is correct
17 Correct 906 ms 25744 KB Output is correct
18 Correct 865 ms 23184 KB Output is correct
19 Correct 513 ms 22108 KB Output is correct
20 Correct 700 ms 22360 KB Output is correct
21 Correct 356 ms 19860 KB Output is correct
22 Correct 482 ms 21300 KB Output is correct
23 Correct 588 ms 23540 KB Output is correct
24 Correct 456 ms 20620 KB Output is correct
25 Correct 1197 ms 27004 KB Output is correct
26 Correct 1198 ms 27256 KB Output is correct
27 Correct 1183 ms 26516 KB Output is correct
28 Correct 1438 ms 28764 KB Output is correct
29 Correct 1407 ms 28568 KB Output is correct
30 Correct 1434 ms 28444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 21484 KB Output is correct
2 Correct 400 ms 21164 KB Output is correct
3 Correct 689 ms 23276 KB Output is correct
4 Correct 1303 ms 28556 KB Output is correct
5 Correct 582 ms 21360 KB Output is correct
6 Correct 693 ms 21584 KB Output is correct
7 Correct 992 ms 25472 KB Output is correct
8 Correct 581 ms 23320 KB Output is correct
9 Correct 759 ms 23920 KB Output is correct
10 Correct 1303 ms 26780 KB Output is correct
11 Correct 1330 ms 26668 KB Output is correct
12 Correct 1570 ms 30332 KB Output is correct
13 Correct 1472 ms 30028 KB Output is correct
14 Correct 1413 ms 28416 KB Output is correct
15 Correct 1239 ms 25504 KB Output is correct
16 Correct 1182 ms 25856 KB Output is correct
17 Correct 793 ms 23508 KB Output is correct
18 Correct 492 ms 21476 KB Output is correct
19 Correct 399 ms 20216 KB Output is correct
20 Correct 342 ms 20352 KB Output is correct
21 Correct 371 ms 22676 KB Output is correct
22 Correct 764 ms 24596 KB Output is correct
23 Correct 427 ms 19980 KB Output is correct
24 Correct 1012 ms 24076 KB Output is correct
25 Correct 1376 ms 29072 KB Output is correct
26 Correct 1336 ms 27156 KB Output is correct
27 Correct 1291 ms 26864 KB Output is correct
28 Correct 1197 ms 26652 KB Output is correct
29 Correct 1227 ms 24892 KB Output is correct
30 Correct 1849 ms 28620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 12172 KB Output is correct
2 Correct 120 ms 11660 KB Output is correct
3 Correct 129 ms 11780 KB Output is correct
4 Correct 126 ms 11572 KB Output is correct
5 Correct 127 ms 11780 KB Output is correct
6 Correct 134 ms 11904 KB Output is correct
7 Correct 126 ms 11824 KB Output is correct
8 Correct 125 ms 11816 KB Output is correct
9 Correct 136 ms 12040 KB Output is correct
10 Correct 138 ms 12040 KB Output is correct
11 Correct 141 ms 12260 KB Output is correct
12 Correct 143 ms 12388 KB Output is correct
13 Correct 149 ms 12456 KB Output is correct
14 Correct 138 ms 12032 KB Output is correct
15 Correct 141 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 12700 KB Output is correct
2 Correct 367 ms 16360 KB Output is correct
3 Correct 165 ms 12104 KB Output is correct
4 Correct 203 ms 15260 KB Output is correct
5 Correct 154 ms 12244 KB Output is correct
6 Correct 310 ms 15444 KB Output is correct
7 Correct 159 ms 12152 KB Output is correct
8 Correct 267 ms 14552 KB Output is correct
9 Correct 352 ms 16448 KB Output is correct
10 Correct 409 ms 19224 KB Output is correct
11 Correct 193 ms 15228 KB Output is correct
12 Correct 151 ms 12448 KB Output is correct
13 Correct 298 ms 15872 KB Output is correct
14 Correct 155 ms 12144 KB Output is correct
15 Correct 237 ms 14232 KB Output is correct
16 Correct 313 ms 16272 KB Output is correct
17 Correct 314 ms 16696 KB Output is correct
18 Correct 335 ms 16644 KB Output is correct
19 Correct 246 ms 14244 KB Output is correct
20 Correct 405 ms 16980 KB Output is correct
21 Correct 472 ms 21484 KB Output is correct
22 Correct 400 ms 21164 KB Output is correct
23 Correct 689 ms 23276 KB Output is correct
24 Correct 1303 ms 28556 KB Output is correct
25 Correct 582 ms 21360 KB Output is correct
26 Correct 693 ms 21584 KB Output is correct
27 Correct 992 ms 25472 KB Output is correct
28 Correct 581 ms 23320 KB Output is correct
29 Correct 759 ms 23920 KB Output is correct
30 Correct 1303 ms 26780 KB Output is correct
31 Correct 1330 ms 26668 KB Output is correct
32 Correct 1570 ms 30332 KB Output is correct
33 Correct 1472 ms 30028 KB Output is correct
34 Correct 1413 ms 28416 KB Output is correct
35 Correct 1239 ms 25504 KB Output is correct
36 Correct 821 ms 23548 KB Output is correct
37 Correct 906 ms 25744 KB Output is correct
38 Correct 865 ms 23184 KB Output is correct
39 Correct 513 ms 22108 KB Output is correct
40 Correct 700 ms 22360 KB Output is correct
41 Correct 356 ms 19860 KB Output is correct
42 Correct 482 ms 21300 KB Output is correct
43 Correct 588 ms 23540 KB Output is correct
44 Correct 456 ms 20620 KB Output is correct
45 Correct 1197 ms 27004 KB Output is correct
46 Correct 1198 ms 27256 KB Output is correct
47 Correct 1183 ms 26516 KB Output is correct
48 Correct 1438 ms 28764 KB Output is correct
49 Correct 1407 ms 28568 KB Output is correct
50 Correct 1434 ms 28444 KB Output is correct
51 Correct 1182 ms 25856 KB Output is correct
52 Correct 793 ms 23508 KB Output is correct
53 Correct 492 ms 21476 KB Output is correct
54 Correct 399 ms 20216 KB Output is correct
55 Correct 342 ms 20352 KB Output is correct
56 Correct 371 ms 22676 KB Output is correct
57 Correct 764 ms 24596 KB Output is correct
58 Correct 427 ms 19980 KB Output is correct
59 Correct 1012 ms 24076 KB Output is correct
60 Correct 1376 ms 29072 KB Output is correct
61 Correct 1336 ms 27156 KB Output is correct
62 Correct 1291 ms 26864 KB Output is correct
63 Correct 1197 ms 26652 KB Output is correct
64 Correct 1227 ms 24892 KB Output is correct
65 Correct 1849 ms 28620 KB Output is correct
66 Correct 132 ms 12172 KB Output is correct
67 Correct 120 ms 11660 KB Output is correct
68 Correct 129 ms 11780 KB Output is correct
69 Correct 126 ms 11572 KB Output is correct
70 Correct 127 ms 11780 KB Output is correct
71 Correct 134 ms 11904 KB Output is correct
72 Correct 126 ms 11824 KB Output is correct
73 Correct 125 ms 11816 KB Output is correct
74 Correct 136 ms 12040 KB Output is correct
75 Correct 138 ms 12040 KB Output is correct
76 Correct 141 ms 12260 KB Output is correct
77 Correct 143 ms 12388 KB Output is correct
78 Correct 149 ms 12456 KB Output is correct
79 Correct 138 ms 12032 KB Output is correct
80 Correct 141 ms 12112 KB Output is correct
81 Correct 1070 ms 25184 KB Output is correct
82 Correct 582 ms 23036 KB Output is correct
83 Correct 652 ms 24036 KB Output is correct
84 Correct 523 ms 22644 KB Output is correct
85 Correct 648 ms 23636 KB Output is correct
86 Correct 625 ms 23224 KB Output is correct
87 Correct 404 ms 18668 KB Output is correct
88 Correct 317 ms 17820 KB Output is correct
89 Correct 470 ms 21516 KB Output is correct
90 Correct 1261 ms 25284 KB Output is correct
91 Correct 1210 ms 26876 KB Output is correct
92 Correct 1334 ms 28652 KB Output is correct
93 Correct 1212 ms 27316 KB Output is correct
94 Correct 1419 ms 30848 KB Output is correct
95 Correct 1262 ms 26764 KB Output is correct
96 Correct 1221 ms 25640 KB Output is correct
97 Correct 1440 ms 29956 KB Output is correct
98 Correct 1395 ms 28604 KB Output is correct
99 Correct 1218 ms 25104 KB Output is correct
100 Correct 1491 ms 28776 KB Output is correct