結果

問題 No.387 ハンコ
ユーザー antaanta
提出日時 2016-06-24 00:02:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 3,134 ms / 5,000 ms
コード長 3,355 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 85,416 KB
実行使用メモリ 62,532 KB
最終ジャッジ日時 2024-04-20 00:06:38
合計ジャッジ時間 24,354 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,066 ms
61,988 KB
testcase_01 AC 3,134 ms
61,608 KB
testcase_02 AC 1,618 ms
62,296 KB
testcase_03 AC 1,633 ms
61,020 KB
testcase_04 AC 1,173 ms
57,620 KB
testcase_05 AC 1,960 ms
61,356 KB
testcase_06 AC 2,526 ms
61,972 KB
testcase_07 AC 1,717 ms
61,036 KB
testcase_08 AC 1,599 ms
62,532 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;
        int H = 1024, LogH = 10;
        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[][] sums = new long[X * 2 + 2][LogH];
        int[] ans = new int[X * 2 * 64];
        for(int i = 0; i < V; ) {
            for(long[] x : sums)
                Arrays.fill(x, 0L);
            for(int y = 0; y < H && i < V; ++ y, ++ i) {
                Arrays.fill(row, 0L);
                for(int shift : shifts[i])
                    shiftOr(row, B, X, shift);
                for(int j = 0; j < X * 2; ++ j) {
                    long[] sum = sums[j];
                    long c = row[j];
                    { long t = sum[0] & c; sum[0] ^= c; c = t; }
                    { long t = sum[1] & c; sum[1] ^= c; c = t; }
                    { long t = sum[2] & c; sum[2] ^= c; c = t; }
                    { long t = sum[3] & c; sum[3] ^= c; c = t; }
                    { long t = sum[4] & c; sum[4] ^= c; c = t; }
                    { long t = sum[5] & c; sum[5] ^= c; c = t; }
                    { long t = sum[6] & c; sum[6] ^= c; c = t; }
                    { long t = sum[7] & c; sum[7] ^= c; c = t; }
                    { long t = sum[8] & c; sum[8] ^= c; c = t; }
                    sum[9] ^= c;
                }
            }
            for(int j = 0; j < X * 2; ++ j) {
                for(int k = 0; k < LogH; ++ k) {
                    long t = sums[j][k];
                    for(int x = 0; x < 64; ++ x) {
                        ans[j * 64 + x] += (int)(t & 1) << k;
                        t >>>= 1;
                    }
                }
            }
        }
        for(int i = 0; i < N * 2 - 1; ++ i)
            System.out.println(ans[i] % 2 != 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