This repository was archived by the owner on Dec 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSW5644.java
More file actions
142 lines (119 loc) · 4.35 KB
/
SW5644.java
File metadata and controls
142 lines (119 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import java.util.Scanner;
public class SW5644 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
for (int test_case = 1; test_case <= tc; test_case++) {
int m = sc.nextInt();
int a = sc.nextInt();
int[] aMove = new int[m + 1];
int[] bMove = new int[m + 1];
for (int i = 1; i <= m; i++) {
aMove[i] = sc.nextInt();
}
for (int i = 1; i <= m; i++) {
bMove[i] = sc.nextInt();
}
int[][][] map = new int[11][11][2];
for (int i = 1; i <= a; i++) {
int y = sc.nextInt();
int x = sc.nextInt();
map[x][y][0] = sc.nextInt();
map[x][y][1] = sc.nextInt();
}
int ax = 1;
int ay = 1;
int bx = 10;
int by = 10;
int answer = 0;
for (int move = 0; move <= m; move++) {
int[] aStation = new int[a + 1];
int[] bStation = new int[a + 1];
switch (aMove[move]) {
case 0:
break;
case 1:
ax--;
break;
case 2:
ay++;
break;
case 3:
ax++;
break;
case 4:
ay--;
break;
}
switch (bMove[move]) {
case 0:
break;
case 1:
bx--;
break;
case 2:
by++;
break;
case 3:
bx++;
break;
case 4:
by--;
break;
}
int index = 0;
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
if (map[i][j][0] > 0) {
index++;
if (distance(i, j, ax, ay) <= map[i][j][0]) {
aStation[index] = map[i][j][1];
}
if (distance(i, j, bx, by) <= map[i][j][0]) {
bStation[index] = map[i][j][1];
}
}
}
}
int aIndex = 0;
int bIndex = 0;
int aPrevious = 0;
int bPrevious = 0;
int aMax = 0;
int bMax = 0;
for (int i = 1; i <= a; i++) {
if (aStation[i] > aMax) {
aPrevious = aIndex;
aMax = aStation[i];
aIndex = i;
}
if (bStation[i] > bMax) {
bPrevious = bIndex;
bMax = bStation[i];
bIndex = i;
}
}
for (int i = aIndex + 1; i <= a; i++) {
if (aStation[i] > aStation[aPrevious]) {
aPrevious = i;
}
}
for (int i = bIndex + 1; i <= a; i++) {
if (bStation[i] > bStation[bPrevious]) {
bPrevious = i;
}
}
if (aIndex == bIndex) {
answer += Math.max(Math.max((aStation[aIndex] + bStation[bIndex]) / 2, aStation[aIndex] + bStation[bPrevious]),aStation[aPrevious] + bStation[bIndex]);
}
else {
answer += aStation[aIndex] + bStation[bIndex];
}
}
System.out.println("#" + test_case + " " + answer);
}
}
public static int distance(int a1, int b1, int a2, int b2) {
return Math.abs(a1 - a2) + Math.abs(b1 - b2);
}
}