結果

問題 No.387 ハンコ
ユーザー antaanta
提出日時 2016-06-24 00:07:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,890 ms / 5,000 ms
コード長 2,178 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 81,912 KB
実行使用メモリ 76,420 KB
最終ジャッジ日時 2024-04-20 00:10:43
合計ジャッジ時間 20,135 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,890 ms
71,976 KB
testcase_01 AC 1,751 ms
72,696 KB
testcase_02 AC 1,687 ms
76,420 KB
testcase_03 AC 1,646 ms
72,156 KB
testcase_04 AC 919 ms
69,600 KB
testcase_05 AC 1,530 ms
69,856 KB
testcase_06 AC 1,760 ms
71,980 KB
testcase_07 AC 1,783 ms
73,060 KB
testcase_08 AC 1,605 ms
73,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package com.example;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N], b = new int[N];
        for(int i = 0; i < N; ++ i)
            a[i] = sc.nextInt();
        for(int i = 0; i < N; ++ i)
            b[i] = sc.nextInt();
        int X = (N - 1) / 64 + 1;
        long[] B = new long[X * 2 + 2];
        for(int i = 0; i < N; ++ i) if(b[i] == 1)
            B[i / 64] |= 1L << i % 64;
        List<Long> values = new ArrayList<Long>();
        for(int i = 0; i < N; ++ i)
            values.add((long)a[i] << 32 | i);
        Collections.sort(values);
        int V = 0;
        int[][] shifts = new int[N][];
        int[] tmp = new int[N];
        for(int i = 0, j; i < N; i = j) {
            int k = 0;
            for(j = i; j < N && values.get(j) >>> 32 == values.get(i) >>> 32; ++ j)
                tmp[k ++] = values.get(j).intValue();
            shifts[V] = Arrays.copyOf(tmp, k);
            ++ V;
        }
        long[] row = new long[X * 2 + 2];
        long[] C = new long[X * 2];
        for(int i = 0; i < V; ++ i) {
            int Y = X + shifts[i][shifts[i].length - 1] / 64 + 1;
            Arrays.fill(row, 0, Y, 0L);
            for(int shift : shifts[i])
                shiftOr(row, B, X, shift);
            for(int j = 0; j < Y; ++ j)
                C[j] ^= row[j];
        }
        for(int i = 0; i < N * 2 - 1; ++ i)
            System.out.println((C[i / 64] >>> (i % 64) & 1) != 0 ? "ODD" : "EVEN");
    }

    static void shiftOr(long[] x, long[] y, int N, int shift) {
        if(N <= 0) return;
        int offset = shift / 64;
        shift %= 64;
        if(shift == 0) {
            for(int i = 0; i < N; ++ i)
                x[offset + i] |= y[i];
        }else {
            int shift2 = 64 - shift;
            x[offset] |= y[0] << shift;
            for(int i = 0; i < N - 1; ++ i)
                x[offset+ i + 1] |= y[i + 1] << shift | y[i] >>> shift2;
            x[offset + N] |= y[N - 1] >>> shift2;
        }
    }
}
0