結果

問題 No.387 ハンコ
ユーザー lavoxlavox
提出日時 2021-09-18 21:11:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,258 ms / 5,000 ms
コード長 3,249 bytes
コンパイル時間 2,937 ms
コンパイル使用メモリ 79,096 KB
実行使用メモリ 63,620 KB
最終ジャッジ日時 2024-06-30 19:19:43
合計ジャッジ時間 13,723 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,258 ms
62,836 KB
testcase_01 AC 1,188 ms
63,620 KB
testcase_02 AC 859 ms
60,072 KB
testcase_03 AC 861 ms
59,704 KB
testcase_04 AC 327 ms
60,628 KB
testcase_05 AC 656 ms
62,384 KB
testcase_06 AC 885 ms
62,720 KB
testcase_07 AC 968 ms
60,496 KB
testcase_08 AC 958 ms
60,216 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