結果

問題 No.5016 Worst Mayor
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-04-29 14:30:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 518 ms / 2,000 ms
コード長 7,057 bytes
コンパイル時間 3,073 ms
コンパイル使用メモリ 91,060 KB
実行使用メモリ 79,968 KB
スコア 105,373,984
平均クエリ数 400.00
最終ジャッジ日時 2023-04-29 14:30:42
合計ジャッジ時間 30,974 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 493 ms
76,888 KB
testcase_01 AC 501 ms
77,424 KB
testcase_02 AC 468 ms
77,144 KB
testcase_03 AC 483 ms
74,856 KB
testcase_04 AC 484 ms
76,428 KB
testcase_05 AC 477 ms
76,224 KB
testcase_06 AC 488 ms
76,980 KB
testcase_07 AC 472 ms
77,016 KB
testcase_08 AC 472 ms
77,112 KB
testcase_09 AC 476 ms
76,444 KB
testcase_10 AC 478 ms
75,996 KB
testcase_11 AC 468 ms
76,264 KB
testcase_12 AC 480 ms
76,744 KB
testcase_13 AC 484 ms
78,660 KB
testcase_14 AC 463 ms
76,640 KB
testcase_15 AC 491 ms
76,668 KB
testcase_16 AC 467 ms
74,752 KB
testcase_17 AC 461 ms
76,920 KB
testcase_18 AC 472 ms
76,480 KB
testcase_19 AC 495 ms
79,968 KB
testcase_20 AC 475 ms
77,488 KB
testcase_21 AC 482 ms
77,324 KB
testcase_22 AC 481 ms
78,920 KB
testcase_23 AC 487 ms
78,864 KB
testcase_24 AC 494 ms
77,188 KB
testcase_25 AC 482 ms
77,248 KB
testcase_26 AC 492 ms
77,120 KB
testcase_27 AC 465 ms
75,144 KB
testcase_28 AC 466 ms
79,860 KB
testcase_29 AC 476 ms
77,204 KB
testcase_30 AC 483 ms
77,432 KB
testcase_31 AC 494 ms
76,512 KB
testcase_32 AC 484 ms
77,008 KB
testcase_33 AC 485 ms
77,300 KB
testcase_34 AC 515 ms
78,720 KB
testcase_35 AC 476 ms
76,452 KB
testcase_36 AC 486 ms
77,228 KB
testcase_37 AC 486 ms
77,196 KB
testcase_38 AC 486 ms
78,412 KB
testcase_39 AC 489 ms
78,280 KB
testcase_40 AC 479 ms
76,712 KB
testcase_41 AC 480 ms
79,780 KB
testcase_42 AC 471 ms
76,584 KB
testcase_43 AC 491 ms
76,988 KB
testcase_44 AC 480 ms
78,156 KB
testcase_45 AC 518 ms
77,396 KB
testcase_46 AC 474 ms
75,792 KB
testcase_47 AC 480 ms
78,228 KB
testcase_48 AC 499 ms
77,252 KB
testcase_49 AC 486 ms
78,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.PriorityQueue;
import java.util.Scanner;

public final class Main {
    private static final int S = 14;
    private int N;
    private int T;
    private int[] A;
    private int[] B;
    private int[] C;
    private int[] D;
    static final Watch watch = new Watch();
    static final XorShift rng = new XorShift(System.nanoTime());

    public static final void main(final String[] args) {
        new Main().run();
    }

    private void run() {
        try (final Scanner in = new Scanner(System.in)) {
            N = in.nextInt();
            watch.init();
            T = in.nextInt();
            A = new int[N];
            B = new int[N];
            C = new int[N];
            D = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt() - 1;
                B[i] = in.nextInt() - 1;
                C[i] = in.nextInt() - 1;
                D[i] = in.nextInt() - 1;
            }
            int[][] counts = new int[2 * S][2 * S];
            for (int i = 0; i < N; i++) {
                int minR = 2 * Math.min(A[i], C[i]);
                int maxR = 2 * Math.max(A[i], C[i]);
                int minC = 2 * Math.min(B[i], D[i]);
                int maxC = 2 * Math.max(B[i], D[i]);
                for (int r = minR; r <= maxR; r++) {
                    for (int c = minC; c <= maxC; c++) {
                        counts[r][c]++;
                    }
                }
            }
            PriorityQueue<Pair<Integer, Integer>> pq = new PriorityQueue<>();
            for (int r = 0; r < 2 * S; r++) {
                for (int c = 0; c < 2 * S; c++) {
                    if ((r + c) % 2 == 0) {
                        continue;
                    }
                    pq.add(new Pair<Integer, Integer>(-counts[r][c], (r << 16) | (c)));
                }
            }
            int prev_capital = (int) 1e6;
            int prev_action = 0;
            for (int t = 0; t < T; t++) {
                int capital = in.nextInt();
                int collaborators = in.nextInt();
                if (capital < 0 && collaborators < 0) {
                    break;
                }
                int highway_revenue = capital - prev_capital + (prev_action == 3 ? -50000 : 0);
                int highway_cost = (int) (1 + 1e7 / Math.sqrt(collaborators));
                if (t < 21) {
                    int action = 2;
                    System.out.println(action);
                    System.out.flush();
                    prev_capital = capital;
                    prev_action = action;
                    continue;
                }
                if (capital >= highway_cost) {
                    int action = 1;
                    int v = pq.poll().second.intValue();
                    int r = v >>> 16;
                    int c = v & ((1 << 16) - 1);
                    if (r % 2 == 0) {
                        assert c % 2 == 1;
                        int r2 = 1 + r / 2;
                        int c2 = 1 + (c - 1) / 2;
                        int c3 = 1 + (c + 1) / 2;
                        System.out.println(action + " " + r2 + " " + c2 + " " + r2 + " " + c3);
                        System.out.flush();
                        prev_capital = capital;
                        prev_action = action;
                        continue;
                    } else {
                        assert c % 2 == 0;
                        int r2 = 1 + (r - 1) / 2;
                        int r3 = 1 + (r + 1) / 2;
                        int c2 = 1 + c / 2;
                        System.out.println(action + " " + r2 + " " + c2 + " " + r3 + " " + c2);
                        System.out.flush();
                        prev_capital = capital;
                        prev_action = action;
                        continue;
                    }
                }
                int action = 3;
                System.out.println(action);
                System.out.flush();
                prev_capital = capital;
                prev_action = action;
            }
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
}

class Watch {
    private long start;

    public Watch() {
        init();
    }

    public double getSecond() {
        return (System.nanoTime() - start) * 1e-9;
    }

    public void init() {
        init(System.nanoTime());
    }

    private void init(long start) {
        this.start = start;
    }

    public String getSecondString() {
        return toString(getSecond());
    }

    public static final String toString(double second) {
        if (second < 60) {
            return String.format("%5.2fs", second);
        } else if (second < 60 * 60) {
            int minute = (int) (second / 60);
            return String.format("%2dm%2ds", minute, (int) (second % 60));
        } else {
            int hour = (int) (second / (60 * 60));
            int minute = (int) (second / 60);
            return String.format("%2dh%2dm%2ds", hour, minute % (60), (int) (second % 60));
        }
    }
}

class XorShift {
    private int w = 88675123;
    private int x = 123456789;
    private int y = 362436069;
    private int z = 521288629;

    public XorShift(long l) {
        x = (int) l;
    }

    public int nextInt() {
        final int t = x ^ (x << 11);
        x = y;
        y = z;
        z = w;
        w = w ^ (w >>> 19) ^ (t ^ (t >>> 8));
        return w;
    }

    public long nextLong() {
        return ((long) nextInt() << 32) ^ (long) nextInt();
    }

    public double nextDouble() {
        return (nextInt() >>> 1) * 4.6566128730773926E-10;
    }

    public int nextInt(int n) {
        return (int) (n * nextDouble());
    }
}

class Pair<T extends Comparable<T>, S> implements Comparable<Pair<T, S>> {
    public T first;
    public S second;

    public Pair(T t, S s) {
        this.first = t;
        this.second = s;
    }

    private int hash = 0;

    @Override
    public int hashCode() {
        if (hash == 0) {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((first == null) ? 0 : first.hashCode());
            result = prime * result + ((second == null) ? 0 : second.hashCode());
            hash = result;
        }
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Pair<T, S> other = (Pair<T, S>) obj;
        if (first == null) {
            if (other.first != null)
                return false;
        } else if (!first.equals(other.first))
            return false;
        if (second == null) {
            if (other.second != null)
                return false;
        } else if (!second.equals(other.second))
            return false;
        return true;
    }

    @Override
    public int compareTo(Pair<T, S> o) {
        return first.compareTo(o.first);
    }
}
0