반응형
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Solution {
static class BC {
int x;
int y;
int c;
int p;
public BC(int x, int y, int c, int p) {
this.x = x;
this.y = y;
this.c = c;
this.p = p;
}
@Override
public String toString() {
return "BC [x=" + x + ", y=" + y + ", c=" + c + ", p=" + p + "]";
}
}
static int answer;
static int M, A, ax, ay, bx, by;
static int[] aPath, bPath;
static BC[] list;
static int[][] dir = {{0,0}, {0,-1}, {1,0}, {0,1}, {-1,0}};
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int T = Integer.parseInt(st.nextToken());
for(int tc=1; tc<=T; tc++) {
st = new StringTokenizer(br.readLine(), " ");
M = Integer.parseInt(st.nextToken());
A = Integer.parseInt(st.nextToken());
aPath = new int[M];
bPath = new int[M];
list = new BC[A];
st = new StringTokenizer(br.readLine(), " ");
for(int i=0; i<M; i++) {
aPath[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine(), " ");
for(int i=0; i<M; i++) {
bPath[i] = Integer.parseInt(st.nextToken());
}
for(int i=0; i<A; i++) {
st = new StringTokenizer(br.readLine(), " ");
list[i] = new BC(
Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken())
);
}
answer = 0;
ax=ay=1;
bx=by=10;
for(int i=0; i<M; i++) {
answer += calc();
ax += dir[aPath[i]][0];
ay += dir[aPath[i]][1];
bx += dir[bPath[i]][0];
by += dir[bPath[i]][1];
}
answer += calc();
System.out.println("#" + tc + " " + answer);
}
}
public static int calc() {
ArrayList<BC> containerA = new ArrayList();
ArrayList<BC> containerB = new ArrayList();
for(int i=0; i<list.length; i++) {
BC bc = list[i];
int aLen = Math.abs(ax-bc.x) + Math.abs(ay-bc.y);
int bLen = Math.abs(bx-bc.x) + Math.abs(by-bc.y);
if(aLen <= bc.c) {
containerA.add(bc);
}
if(bLen <= bc.c) {
containerB.add(bc);
}
}
int value = 0;
// A만 범위안에 있을 때
if(containerB.size() == 0) {
for(BC bc : containerA) {
value = Math.max(bc.p, value);
}
} else if(containerA.size() == 0) {
// B만 범위안에 있을 때
for(BC bc : containerB) {
value = Math.max(bc.p, value);
}
} else if (containerA.size() != 0 && containerB.size() != 0) {
// A B 둘다 범위 안에 있을 떄
for(BC bcA : containerA) {
for(BC bcB : containerB) {
if((bcA.x == bcB.x) && (bcA.y == bcB.y)) {
value = Math.max(value, bcA.p);
} else {
value = Math.max(value, bcA.p+bcB.p);
}
}
}
}
return value;
}
}
반응형
'알고리즘 > SW 역량 테스트' 카테고리의 다른 글
[백준] 19238. 스타트 택시 (0) | 2020.07.16 |
---|---|
[백준] 19237. 어른 상어 (0) | 2020.07.13 |
[백준] 19236. 청소년 상어 (0) | 2020.06.29 |
5658. [모의 SW 역량테스트] 보물상자 비밀번호 (0) | 2020.05.11 |
5650. [모의 SW 역량테스트] 핀볼 게임 (0) | 2020.05.07 |