結果

問題 No.387 ハンコ
ユーザー lavoxlavox
提出日時 2021-09-18 21:11:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,212 ms / 5,000 ms
コード長 3,249 bytes
コンパイル時間 3,450 ms
コンパイル使用メモリ 75,536 KB
実行使用メモリ 64,972 KB
最終ジャッジ日時 2023-09-13 09:34:57
合計ジャッジ時間 14,317 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,176 ms
64,972 KB
testcase_01 AC 1,212 ms
64,228 KB
testcase_02 AC 856 ms
59,780 KB
testcase_03 AC 857 ms
60,056 KB
testcase_04 AC 344 ms
61,620 KB
testcase_05 AC 633 ms
63,308 KB
testcase_06 AC 600 ms
62,748 KB
testcase_07 AC 1,086 ms
60,548 KB
testcase_08 AC 898 ms
60,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		Main o = new Main();
		o.solve();
	}

	public void solve() {
		FastScanner sc = new FastScanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt() - 1;
		}
		long[] b = new long[N / 64 + 1];
		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			if ( x == 1 ) b[i / 64] |= (1L << (i % 64));
		}

		final int MAX = 100000;
		ArrayList<Integer>[] pos = new ArrayList[MAX];
		for (int i = 0; i < MAX; i++) {
			pos[i] = new ArrayList<>();
		}
		for (int i = 0; i < N; i++) {
			pos[a[i]].add(i);
		}

		long[] ans = new long[(2 * N - 1)/64 + 1];
		for (int i = 0; i < MAX; i++) {
			if ( pos[i].size() == 0 ) continue;

			long[] bs = new long[(2 * N - 1)/64 + 1];
			for ( int x : pos[i] ) {
				int xo = x / 64;
				int xr = x % 64;
				for ( int j = 0 ; j <= N / 64 ; j++ ) {
					bs[j + xo] |= (b[j] << xr);
					if ( xr != 0 && j + xo + 1 < (2 * N - 1)/64 + 1 ) bs[j + xo + 1] |= (b[j] >>> (64 - xr));
				}
			}
			for ( int j = 0 ; j < bs.length ; j++ ) {
				ans[j] ^= bs[j];
			}
		}

		StringBuilder str = new StringBuilder();
		for ( int i = 0 ; i < 2 * N - 1 ; i++ ) {
			if ( ((ans[i / 64] >>> (i % 64)) & 1L) == 1L ) {
				str.append("ODD\n");
			} else {
				str.append("EVEN\n");
			}
		}
		System.out.print(str.toString());
	}

	class FastScanner {
		private final InputStream in;
		private final byte[] buf = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		FastScanner( InputStream source ) { this.in = source; }
		private boolean hasNextByte() {
			if ( ptr < buflen ) return true;
			else {
				ptr = 0;
				try { buflen = in.read(buf); } catch (IOException e) { e.printStackTrace(); }
				if ( buflen <= 0 ) return false;
			}
			return true;
		} 
		private int readByte() { if ( hasNextByte() ) return buf[ptr++]; else return -1; } 
		private boolean isPrintableChar( int c ) { return 33 <= c && c <= 126; }
		private boolean isNumeric( int c ) { return '0' <= c && c <= '9'; }
		private void skipToNextPrintableChar() { while ( hasNextByte() && !isPrintableChar(buf[ptr]) ) ptr++; }
		public boolean hasNext() { skipToNextPrintableChar(); return hasNextByte(); }
		public String next() {
			if ( !hasNext() ) throw new NoSuchElementException();
			StringBuilder ret = new StringBuilder();
			int b = readByte();
			while ( isPrintableChar(b) ) { ret.appendCodePoint(b); b = readByte(); }
			return ret.toString();
		}
		public long nextLong() {
			if ( !hasNext() ) throw new NoSuchElementException();
			long ret = 0;
			int b = readByte();
			boolean negative = false;
			if ( b == '-' ) { negative = true; if ( hasNextByte() ) b = readByte(); }
			if ( !isNumeric(b) ) throw new NumberFormatException();
			while ( true ) {
				if ( isNumeric(b) ) ret = ret * 10 + b - '0';
				else if ( b == -1 || !isPrintableChar(b) ) return negative ? -ret : ret;
				else throw new NumberFormatException();
				b = readByte();
			}
		}
		public int nextInt() { return (int)nextLong(); }
		public double nextDouble() { return Double.parseDouble(next()); }
	}
}
0