結果
| 問題 |
No.1225 I hate I hate Matrix Construction
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2020-09-11 21:45:15 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 213 ms / 2,000 ms |
| コード長 | 1,345 bytes |
| コンパイル時間 | 2,119 ms |
| コンパイル使用メモリ | 77,728 KB |
| 実行使用メモリ | 43,908 KB |
| 最終ジャッジ日時 | 2024-12-27 10:45:09 |
| 合計ジャッジ時間 | 10,031 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 35 |
ソースコード
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));
}
}
ks2m