結果

問題 No.24 数当てゲーム
ユーザー gahougahou
提出日時 2022-05-15 20:53:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 38 ms / 5,000 ms
コード長 3,342 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 49,416 KB
最終ジャッジ日時 2023-10-11 09:17:10
合計ジャッジ時間 3,325 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
49,280 KB
testcase_01 AC 37 ms
49,416 KB
testcase_02 AC 36 ms
49,396 KB
testcase_03 AC 38 ms
49,080 KB
testcase_04 AC 36 ms
49,280 KB
testcase_05 AC 37 ms
49,168 KB
testcase_06 AC 37 ms
49,064 KB
testcase_07 AC 36 ms
49,276 KB
testcase_08 AC 36 ms
49,208 KB
testcase_09 AC 35 ms
49,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Deque;
import java.util.ArrayDeque;
import java.util.Collections;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int N = reader.nextInt();
		int[][] q   = new int[N][4];
		boolean[] b = new boolean[N];
		for(int i=0; i<N; i++) {
			for (int j=0; j<4; j++) {
				q[i][j] = reader.nextInt();
			}
			b[i] = (reader.next().equals("YES"));
		}

		boolean[] ans = new boolean[10];
		for (int i=0; i<10; i++) ans[i] = true;
		for (int i=0; i<N; i++) {
			if(b[i]) {
				for (int j=0; j<10; j++) {
					boolean ischange = true;
					for (int k=0; k<4; k++) {
						if (q[i][k] == j) ischange = false;
					}
					if (ischange) ans[j] = false;
				}
			}else{
				for (int j=0; j<4; j++) {
					ans[q[i][j]] = false;
				}
			}
		}

		for (int i=0; i<10; i++) {
			if (ans[i]) System.out.println(i);
		}
	}

	public static void output2DArray(boolean[][] a, int r) {
		for (int x=0; x<r; x++) {
			for (int y=0; y<r; y++) {
				if(a[x][y]) System.out.print("o");
				else System.out.print("x");
			}
			System.out.println();
		}
		System.out.println();
	}
	
	public static void outputArray(long[] a) {
		int size = a.length;
		for (int i=0; i<size; i++) {
			if (i == size-1) System.out.print(a[i]);
			else System.out.print(a[i] + " ");
		}
		System.out.println();
	}

	public static void outputList(ArrayList a) {
		int size = a.size();
		for (int i=0; i<size; i++) {
			if (i == size-1) System.out.print(a.get(i));
			else System.out.print(a.get(i) + " ");
		}
		System.out.println();
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}
0