結果

問題 No.1225 I hate I hate Matrix Construction
ユーザー ks2mks2m
提出日時 2020-09-11 21:45:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 73,948 KB
実行使用メモリ 59,240 KB
最終ジャッジ日時 2023-08-27 13:42:53
合計ジャッジ時間 9,496 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,780 KB
testcase_01 AC 117 ms
55,880 KB
testcase_02 AC 119 ms
56,344 KB
testcase_03 AC 124 ms
56,116 KB
testcase_04 AC 166 ms
58,788 KB
testcase_05 AC 128 ms
56,088 KB
testcase_06 AC 156 ms
58,152 KB
testcase_07 AC 132 ms
55,836 KB
testcase_08 AC 139 ms
55,968 KB
testcase_09 AC 176 ms
56,356 KB
testcase_10 AC 175 ms
56,228 KB
testcase_11 AC 193 ms
58,356 KB
testcase_12 AC 186 ms
56,240 KB
testcase_13 AC 136 ms
56,284 KB
testcase_14 AC 123 ms
55,752 KB
testcase_15 AC 178 ms
56,640 KB
testcase_16 AC 181 ms
56,224 KB
testcase_17 AC 197 ms
59,168 KB
testcase_18 AC 192 ms
56,748 KB
testcase_19 AC 185 ms
56,892 KB
testcase_20 AC 174 ms
56,380 KB
testcase_21 AC 185 ms
56,748 KB
testcase_22 AC 180 ms
56,356 KB
testcase_23 AC 182 ms
56,376 KB
testcase_24 AC 181 ms
56,556 KB
testcase_25 AC 184 ms
58,488 KB
testcase_26 AC 171 ms
56,280 KB
testcase_27 AC 117 ms
56,088 KB
testcase_28 AC 191 ms
58,908 KB
testcase_29 AC 177 ms
56,084 KB
testcase_30 AC 186 ms
58,628 KB
testcase_31 AC 190 ms
58,864 KB
testcase_32 AC 198 ms
58,068 KB
testcase_33 AC 181 ms
56,416 KB
testcase_34 AC 200 ms
59,240 KB
testcase_35 AC 187 ms
58,872 KB
testcase_36 AC 165 ms
55,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] s = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.nextInt();
		}
		int[] t = new int[n];
		for (int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
		}
		sc.close();

		int[][] a = new int[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(a[i], -1);
		}

		for (int i = 0; i < n; i++) {
			if (s[i] == 0) {
				for (int j = 0; j < n; j++) {
					a[i][j] = 0;
				}
			}
			if (s[i] == 2) {
				for (int j = 0; j < n; j++) {
					a[i][j] = 1;
				}
			}
		}
		for (int j = 0; j < n; j++) {
			if (t[j] == 0) {
				for (int i = 0; i < n; i++) {
					if (a[i][j] == 1) {
						throw new Exception();
					}
					a[i][j] = 0;
				}
			}
			if (t[j] == 2) {
				for (int i = 0; i < n; i++) {
					if (a[i][j] == 0) {
						throw new Exception();
					}
					a[i][j] = 1;
				}
			}
		}

		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (a[i][j] == 1) {
					cnt++;
					s[i] = -1;
					t[j] = -1;
				}
			}
		}

		int cs = 0;
		int ct = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == 1) {
				cs++;
			}
			if (t[i] == 1) {
				ct++;
			}
		}
		System.out.println(cnt + Math.max(cs, ct));
	}
}
0