結果
| 問題 |
No.359 門松行列
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2016-04-17 22:50:25 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,928 bytes |
| コンパイル時間 | 2,353 ms |
| コンパイル使用メモリ | 79,900 KB |
| 実行使用メモリ | 57,104 KB |
| 最終ジャッジ日時 | 2024-10-04 10:42:32 |
| 合計ジャッジ時間 | 6,587 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 14 |
ソースコード
package no359;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;
public class Main {
public static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int t = sc.nextInt();
for(int tt=0;tt<t;tt++) {
solve();
}
}
public static void solve() {
int l = sc.nextInt();
int[][] a = new int[3][3];
TreeSet<Integer> ts = new TreeSet<>();
int[] r = new int[2];
int[] c = new int[2];
int ind = 0;
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
int h = sc.nextInt();
a[i][j] = h;
if (h == 0) {
r[ind] = i;
c[ind] = j;
ind++;
continue;
}
if (h < l) {
ts.add(h);
}
if (l - h >= 1) {
ts.add(l-h);
}
}
}
ts.add(0);
ts.add(l);
ArrayList<Integer> ev1 = new ArrayList<>(ts);
ArrayList<Pair> ev2 = new ArrayList<>();
for(int i=1;i<ev1.size();i++) {
int h = ev1.get(i);
if (i < ev1.size() - 1) {
ev2.add(new Pair(h, 1));
}
int h2 = ev1.get(i-1);
if (h - h2 >= 2) {
ev2.add(new Pair(h-1, h - h2 - 1));
}
}
int ans = 0;
for(Pair p: ev2) {
a[r[0]][c[0]] = p.x;
a[r[1]][c[1]] = l - p.x;
if (isKadomatsuMatrix(a)) {
ans += p.weight;
}
}
System.out.println(ans);
}
static class Pair {
int x;
int weight;
public Pair(int x, int weight) {
super();
this.x = x;
this.weight = weight;
}
}
public static boolean isKadomatsuSequence(long a,long b,long c) {
if (a == b || b == c || a == c) {
return false;
}
return b < a && b < c || b > a && b > c;
}
public static boolean isKadomatsuMatrix(int[][] a) {
for(int i=0;i<3;i++) {
if (!isKadomatsuSequence(a[i][0], a[i][1], a[i][2])) {
return false;
}
if (!isKadomatsuSequence(a[0][i], a[1][i], a[2][i])) {
return false;
}
}
return isKadomatsuSequence(a[0][0], a[1][1], a[2][2]) && isKadomatsuSequence(a[0][2], a[1][1], a[2][0]);
}
}
ぴろず