Submission #433257
Source Code Expand
import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; public class Main { public static void main(String[] args) { HashSet<Integer> al = new HashSet<>(); for(int i=1;i<=25;i++) { al.add(i); } ArrayList<Integer> ei = new ArrayList<>(); ArrayList<Integer> ej = new ArrayList<>(); Scanner sc = new Scanner(System.in); int[][] m = new int[5][5]; for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { m[i][j] = sc.nextInt(); al.remove(m[i][j]); if (m[i][j] == 0) { ei.add(i); ej.add(j); } } } int n = al.size(); if (n > 8) { throw new RuntimeException(); } Integer[] pp = al.toArray(new Integer[0]); int[] p = new int[n]; for(int i=0;i<n;i++) { p[i] = pp[i]; } int ans = 0; do { for(int i=0;i<n;i++) { m[ei.get(i)][ej.get(i)] = p[i]; } if (isValid(m)) { ans++; } } while (nextPermutation(p)); System.out.println(ans); } public static boolean isValid(int[][] m) { for(int i=0;i<3;i++) { for(int j=0;j<5;j++) { if (m[i][j] < m[i+1][j] && m[i+1][j] < m[i+2][j]) { return false; } if (m[i][j] > m[i+1][j] && m[i+1][j] > m[i+2][j]) { return false; } } } for(int i=0;i<5;i++) { for(int j=0;j<3;j++) { if (m[i][j] < m[i][j+1] && m[i][j+1] < m[i][j+2]) { return false; } if (m[i][j] > m[i][j+1] && m[i][j+1] > m[i][j+2]) { return false; } } } return true; } static boolean nextPermutation(int[] p) { for(int a=p.length-2;a>=0;--a) { if(p[a]<p[a+1]) { for(int b=p.length-1;;--b) { if(p[b]>p[a]) { int t = p[a]; p[a] = p[b]; p[b] = t; for(++a, b=p.length-1;a<b;++a,--b) { t = p[a]; p[a] = p[b]; p[b] = t; } return true; } } } } return false; } }
Submission Info
Submission Time | |
---|---|
Task | D - 25個の整数 |
User | piroz95 |
Language | Java8 (OpenJDK 1.8.0) |
Score | 30 |
Code Size | 1914 Byte |
Status | RE |
Exec Time | 566 ms |
Memory | 31200 KB |
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 30 / 30 | 0 / 70 | ||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Subtask1 | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, test-1-01.txt, test-1-02.txt, test-1-03.txt, test-1-04.txt, test-1-05.txt, test-1-06.txt, test-1-07.txt, test-1-08.txt, test-1-09.txt, test-1-10.txt, test-1-11.txt, test-1-12.txt, test-1-13.txt, test-1-14.txt, test-1-15.txt |
Subtask2 | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, test-1-01.txt, test-1-02.txt, test-1-03.txt, test-1-04.txt, test-1-05.txt, test-1-06.txt, test-1-07.txt, test-1-08.txt, test-1-09.txt, test-1-10.txt, test-1-11.txt, test-1-12.txt, test-1-13.txt, test-1-14.txt, test-1-15.txt, test-2-01.txt, test-2-02.txt, test-2-03.txt, test-2-04.txt, test-2-05.txt, test-2-06.txt, test-2-07.txt, test-2-08.txt, test-2-09.txt, test-2-10.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample-01.txt | AC | 508 ms | 29160 KB |
sample-02.txt | AC | 539 ms | 31088 KB |
sample-03.txt | AC | 484 ms | 29136 KB |
sample-04.txt | AC | 480 ms | 29168 KB |
test-1-01.txt | AC | 545 ms | 31024 KB |
test-1-02.txt | AC | 483 ms | 29092 KB |
test-1-03.txt | AC | 482 ms | 29028 KB |
test-1-04.txt | AC | 507 ms | 29600 KB |
test-1-05.txt | AC | 501 ms | 29508 KB |
test-1-06.txt | AC | 534 ms | 30772 KB |
test-1-07.txt | AC | 531 ms | 31016 KB |
test-1-08.txt | AC | 540 ms | 31168 KB |
test-1-09.txt | AC | 547 ms | 31012 KB |
test-1-10.txt | AC | 483 ms | 28976 KB |
test-1-11.txt | AC | 481 ms | 29092 KB |
test-1-12.txt | AC | 535 ms | 31156 KB |
test-1-13.txt | AC | 483 ms | 29092 KB |
test-1-14.txt | AC | 546 ms | 30732 KB |
test-1-15.txt | AC | 566 ms | 31200 KB |
test-2-01.txt | RE | 532 ms | 28984 KB |
test-2-02.txt | RE | 495 ms | 29092 KB |
test-2-03.txt | RE | 485 ms | 29096 KB |
test-2-04.txt | RE | 485 ms | 29220 KB |
test-2-05.txt | RE | 484 ms | 28976 KB |
test-2-06.txt | RE | 483 ms | 29096 KB |
test-2-07.txt | RE | 483 ms | 29096 KB |
test-2-08.txt | RE | 478 ms | 29096 KB |
test-2-09.txt | RE | 478 ms | 29104 KB |
test-2-10.txt | RE | 492 ms | 28940 KB |