ログインしてください。
提出 #73258252
ソースコード 拡げる
import java.io.*;
import java.util.*;
public class Main {
static int N, M, T, U;
static int[][] value;
static int[][] owner;
static int[][] level;
static int myX, myY;
static int[] dx = {1, -1, 0, 0};
static int[] dy = {0, 0, 1, -1};
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
N = Integer.parseInt(br.readLine());
M = Integer.parseInt(br.readLine());
T = Integer.parseInt(br.readLine());
U = Integer.parseInt(br.readLine());
value = new int[N][N];
owner = new int[N][N];
level = new int[N][N];
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
value[i][j] = Integer.parseInt(st.nextToken());
}
}
int[] sx = new int[M];
int[] sy = new int[M];
for (int i = 0; i < M; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
sx[i] = Integer.parseInt(st.nextToken());
sy[i] = Integer.parseInt(st.nextToken());
}
myX = sx[0];
myY = sy[0];
for (int turn = 0; turn < T; turn++) {
// Choose move
int[] move = chooseMove();
out.println(move[0] + " " + move[1]);
out.flush();
// Read turn result
readTurn(br);
myX = getMyPieceX();
myY = getMyPieceY();
}
out.flush();
}
static int[] chooseMove() {
boolean[][] reachable = getReachable();
List<int[]> candidates = new ArrayList<>();
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (reachable[i][j] || isAdjacentToReachable(i, j, reachable)) {
candidates.add(new int[]{i, j});
}
}
}
double bestScore = -1e18;
int[] bestMove = {myX, myY};
for (int[] cell : candidates) {
int x = cell[0], y = cell[1];
double score = evaluate(x, y);
if (score > bestScore) {
bestScore = score;
bestMove = cell;
}
}
return bestMove;
}
static double evaluate(int x, int y) {
int v = value[x][y];
// Empty
if (owner[x][y] == -1) {
return v * 3.0;
}
// Own cell
if (owner[x][y] == 0) {
if (level[x][y] < U)
return v * 2.0;
else
return -1000;
}
// Enemy cell
if (level[x][y] == 1) {
return v * 4.0;
}
return -v; // Avoid attacking strong cells
}
static boolean[][] getReachable() {
boolean[][] visited = new boolean[N][N];
Queue<int[]> q = new LinkedList<>();
q.add(new int[]{myX, myY});
visited[myX][myY] = true;
while (!q.isEmpty()) {
int[] cur = q.poll();
int x = cur[0], y = cur[1];
for (int d = 0; d < 4; d++) {
int nx = x + dx[d];
int ny = y + dy[d];
if (inBounds(nx, ny) && !visited[nx][ny] && owner[nx][ny] == 0) {
visited[nx][ny] = true;
q.add(new int[]{nx, ny});
}
}
}
return visited;
}
static boolean isAdjacentToReachable(int x, int y, boolean[][] reachable) {
for (int d = 0; d < 4; d++) {
int nx = x + dx[d];
int ny = y + dy[d];
if (inBounds(nx, ny) && reachable[nx][ny]) return true;
}
return false;
}
static boolean inBounds(int x, int y) {
return x >= 0 && x < N && y >= 0 && y < N;
}
static void readTurn(BufferedReader br) throws Exception {
// read move destinations
for (int i = 0; i < M; i++) br.readLine();
// read piece end positions
for (int i = 0; i < M; i++) br.readLine();
// read owner
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
owner[i][j] = Integer.parseInt(st.nextToken());
}
}
// read level
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
level[i][j] = Integer.parseInt(st.nextToken());
}
}
}
static int getMyPieceX() {
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (owner[i][j] == 0 && level[i][j] >= 1)
return i;
return myX;
}
static int getMyPieceY() {
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (owner[i][j] == 0 && level[i][j] >= 1)
return j;
return myY;
}
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | A - Multi-Player Territory Game |
| ユーザ | KaranChauhan |
| 言語 | Java24 (OpenJDK 24.0.2) |
| 得点 | 0 |
| コード長 | 5370 Byte |
| 結果 | RE |
| 実行時間 | 52 ms |
| メモリ | 38656 KiB |
ジャッジ結果
| セット名 | test_ALL | ||||
|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 100000000000 | ||||
| 結果 |
|
| セット名 | テストケース |
|---|---|
| test_ALL | test_0000.txt, test_0001.txt, test_0002.txt, test_0003.txt, test_0004.txt, test_0005.txt, test_0006.txt, test_0007.txt, test_0008.txt, test_0009.txt, test_0010.txt, test_0011.txt, test_0012.txt, test_0013.txt, test_0014.txt, test_0015.txt, test_0016.txt, test_0017.txt, test_0018.txt, test_0019.txt, test_0020.txt, test_0021.txt, test_0022.txt, test_0023.txt, test_0024.txt, test_0025.txt, test_0026.txt, test_0027.txt, test_0028.txt, test_0029.txt, test_0030.txt, test_0031.txt, test_0032.txt, test_0033.txt, test_0034.txt, test_0035.txt, test_0036.txt, test_0037.txt, test_0038.txt, test_0039.txt, test_0040.txt, test_0041.txt, test_0042.txt, test_0043.txt, test_0044.txt, test_0045.txt, test_0046.txt, test_0047.txt, test_0048.txt, test_0049.txt, test_0050.txt, test_0051.txt, test_0052.txt, test_0053.txt, test_0054.txt, test_0055.txt, test_0056.txt, test_0057.txt, test_0058.txt, test_0059.txt, test_0060.txt, test_0061.txt, test_0062.txt, test_0063.txt, test_0064.txt, test_0065.txt, test_0066.txt, test_0067.txt, test_0068.txt, test_0069.txt, test_0070.txt, test_0071.txt, test_0072.txt, test_0073.txt, test_0074.txt, test_0075.txt, test_0076.txt, test_0077.txt, test_0078.txt, test_0079.txt, test_0080.txt, test_0081.txt, test_0082.txt, test_0083.txt, test_0084.txt, test_0085.txt, test_0086.txt, test_0087.txt, test_0088.txt, test_0089.txt, test_0090.txt, test_0091.txt, test_0092.txt, test_0093.txt, test_0094.txt, test_0095.txt, test_0096.txt, test_0097.txt, test_0098.txt, test_0099.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| test_0000.txt | RE | 52 ms | 38420 KiB |
| test_0001.txt | RE | 46 ms | 38324 KiB |
| test_0002.txt | RE | 48 ms | 37976 KiB |
| test_0003.txt | RE | 46 ms | 38552 KiB |
| test_0004.txt | RE | 48 ms | 38496 KiB |
| test_0005.txt | RE | 47 ms | 38364 KiB |
| test_0006.txt | RE | 47 ms | 38216 KiB |
| test_0007.txt | RE | 47 ms | 38548 KiB |
| test_0008.txt | RE | 48 ms | 38340 KiB |
| test_0009.txt | RE | 47 ms | 38308 KiB |
| test_0010.txt | RE | 47 ms | 38496 KiB |
| test_0011.txt | WA | 47 ms | 17908 KiB |
| test_0012.txt | RE | 46 ms | 38476 KiB |
| test_0013.txt | RE | 47 ms | 38296 KiB |
| test_0014.txt | WA | 47 ms | 38336 KiB |
| test_0015.txt | RE | 47 ms | 38548 KiB |
| test_0016.txt | RE | 46 ms | 38344 KiB |
| test_0017.txt | WA | 47 ms | 38300 KiB |
| test_0018.txt | RE | 48 ms | 38640 KiB |
| test_0019.txt | RE | 46 ms | 38268 KiB |
| test_0020.txt | RE | 47 ms | 38212 KiB |
| test_0021.txt | WA | 48 ms | 38508 KiB |
| test_0022.txt | RE | 48 ms | 38048 KiB |
| test_0023.txt | WA | 47 ms | 17964 KiB |
| test_0024.txt | RE | 47 ms | 38340 KiB |
| test_0025.txt | RE | 47 ms | 38624 KiB |
| test_0026.txt | RE | 48 ms | 38288 KiB |
| test_0027.txt | RE | 48 ms | 38476 KiB |
| test_0028.txt | WA | 47 ms | 38032 KiB |
| test_0029.txt | RE | 48 ms | 38476 KiB |
| test_0030.txt | WA | 48 ms | 17880 KiB |
| test_0031.txt | RE | 47 ms | 38440 KiB |
| test_0032.txt | RE | 47 ms | 38556 KiB |
| test_0033.txt | RE | 48 ms | 38404 KiB |
| test_0034.txt | RE | 47 ms | 38548 KiB |
| test_0035.txt | RE | 47 ms | 38432 KiB |
| test_0036.txt | RE | 46 ms | 38360 KiB |
| test_0037.txt | RE | 47 ms | 38448 KiB |
| test_0038.txt | RE | 47 ms | 38340 KiB |
| test_0039.txt | RE | 47 ms | 38244 KiB |
| test_0040.txt | RE | 47 ms | 38052 KiB |
| test_0041.txt | RE | 47 ms | 38640 KiB |
| test_0042.txt | RE | 48 ms | 38356 KiB |
| test_0043.txt | RE | 47 ms | 38300 KiB |
| test_0044.txt | RE | 48 ms | 38268 KiB |
| test_0045.txt | RE | 48 ms | 38520 KiB |
| test_0046.txt | RE | 47 ms | 38628 KiB |
| test_0047.txt | RE | 47 ms | 38468 KiB |
| test_0048.txt | RE | 47 ms | 38292 KiB |
| test_0049.txt | RE | 48 ms | 38408 KiB |
| test_0050.txt | RE | 47 ms | 38600 KiB |
| test_0051.txt | WA | 47 ms | 37936 KiB |
| test_0052.txt | RE | 47 ms | 38444 KiB |
| test_0053.txt | RE | 47 ms | 38176 KiB |
| test_0054.txt | RE | 47 ms | 38508 KiB |
| test_0055.txt | RE | 47 ms | 38244 KiB |
| test_0056.txt | RE | 48 ms | 38416 KiB |
| test_0057.txt | RE | 47 ms | 38464 KiB |
| test_0058.txt | RE | 47 ms | 38172 KiB |
| test_0059.txt | RE | 47 ms | 38236 KiB |
| test_0060.txt | RE | 47 ms | 37976 KiB |
| test_0061.txt | RE | 47 ms | 38300 KiB |
| test_0062.txt | RE | 47 ms | 38412 KiB |
| test_0063.txt | RE | 47 ms | 38288 KiB |
| test_0064.txt | RE | 48 ms | 38656 KiB |
| test_0065.txt | RE | 48 ms | 38432 KiB |
| test_0066.txt | RE | 46 ms | 38420 KiB |
| test_0067.txt | RE | 47 ms | 38496 KiB |
| test_0068.txt | WA | 47 ms | 17928 KiB |
| test_0069.txt | RE | 47 ms | 38568 KiB |
| test_0070.txt | WA | 48 ms | 17896 KiB |
| test_0071.txt | RE | 46 ms | 38340 KiB |
| test_0072.txt | RE | 47 ms | 38172 KiB |
| test_0073.txt | WA | 48 ms | 17992 KiB |
| test_0074.txt | RE | 48 ms | 38456 KiB |
| test_0075.txt | RE | 48 ms | 38552 KiB |
| test_0076.txt | RE | 47 ms | 38528 KiB |
| test_0077.txt | RE | 47 ms | 38176 KiB |
| test_0078.txt | RE | 48 ms | 38464 KiB |
| test_0079.txt | WA | 46 ms | 17896 KiB |
| test_0080.txt | RE | 47 ms | 38212 KiB |
| test_0081.txt | RE | 47 ms | 38064 KiB |
| test_0082.txt | RE | 47 ms | 38300 KiB |
| test_0083.txt | RE | 47 ms | 38316 KiB |
| test_0084.txt | RE | 48 ms | 38384 KiB |
| test_0085.txt | RE | 47 ms | 38520 KiB |
| test_0086.txt | WA | 48 ms | 18008 KiB |
| test_0087.txt | RE | 46 ms | 38556 KiB |
| test_0088.txt | RE | 46 ms | 38344 KiB |
| test_0089.txt | WA | 47 ms | 17944 KiB |
| test_0090.txt | RE | 47 ms | 38172 KiB |
| test_0091.txt | RE | 47 ms | 38444 KiB |
| test_0092.txt | WA | 47 ms | 38476 KiB |
| test_0093.txt | RE | 47 ms | 38524 KiB |
| test_0094.txt | RE | 47 ms | 38512 KiB |
| test_0095.txt | RE | 46 ms | 38568 KiB |
| test_0096.txt | RE | 47 ms | 38548 KiB |
| test_0097.txt | RE | 48 ms | 38228 KiB |
| test_0098.txt | RE | 47 ms | 38424 KiB |
| test_0099.txt | RE | 47 ms | 38340 KiB |