結果

問題 No.1121 Social Distancing in Cinema
ユーザー ApassApass
提出日時 2020-07-29 10:14:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 4,177 bytes
コンパイル時間 5,469 ms
コンパイル使用メモリ 82,076 KB
実行使用メモリ 61,568 KB
最終ジャッジ日時 2023-09-11 07:11:10
合計ジャッジ時間 26,425 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
51,068 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class SocialDistancingInCinema {
    //@formatter:off
    static final int[][] forbiddenNeighbors = {
                            {-4,-3,-2,-1, 0, 1, 2, 3, 4,},  // -9
                         {-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5,},  // -8
                   {-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7,},  // -7
                   {-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7,},  // -6
                {-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8,},  // -5
             {-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,},  // -4
             {-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,},  // -3
             {-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,},  // -2
             {-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,},  // -1
             {-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,},  // 0
             {-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,},  // 1
             {-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,},  // 2
             {-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,},  // 3
             {-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,},  // 4
                {-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8,},  // 5
                   {-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7,},  // 6
                   {-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7,},  // 7
                         {-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5,},  // 8
                            {-4,-3,-2,-1, 0, 1, 2, 3, 4,},  // 9
    };
    //@formatter:on
    static final int[] length = {9, 11, 15, 15, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 17, 15, 15, 11, 9};
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        ArrayList<Integer> answer = solve();
        pw.println(answer.size());
        for (int i : answer) {
            pw.print(i + " ");
        }
        pw.println();
        pw.close();
    }

    private static ArrayList<Integer> solve() throws IOException {
        int N = readInt();
        System.out.println(N);
        int[][] index = new int[518][518];
        boolean[][] present = new boolean[518][518];
        for (int i = 1; i <= N; i++) {
            int x = readInt() + 8;
            int y = readInt() + 8;
            index[x][y] = i;
            present[x][y] = true;
        }

        ArrayList<Integer> selected = new ArrayList<>();
        int direction = 1;
        for (int i = 9; i <= 508; i++) {
            int keepDirection = 1;
            if (direction == 1) {
                for (int j = 9; j <= 508; j++) {
                    if (present[i][j]) {
                        selected.add(index[i][j]);
                        for (int k = 0, r = -9; k < 19; k++, r++) {
                            for (int l = length[k] - 1; l >= 0; l--) {
                                present[i + r][j + forbiddenNeighbors[k][l]] = false;
                            }
                        }
                        keepDirection = -1;
                    }
                }
            } else {
                for (int j = 508; j >= 9; j--) {
                    if (present[i][j]) {
                        selected.add(index[i][j]);
                        for (int k = 0, r = -9; k < 19; k++, r++) {
                            for (int l = length[k] - 1; l >= 0; l--) {
                                present[i + r][j + forbiddenNeighbors[k][l]] = false;
                            }
                        }
                        keepDirection = -1;
                    }
                }
            }
            direction *= keepDirection;
        }

        return selected;
    }
}
0