Submission #1293530
Source Code Expand
import java.util.LinkedList; import java.util.Scanner; public class Main { static int[][] map; static final int INF =1000000007; static long cnt=0; static LinkedList<Integer> usable; public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ //枝刈り?間に合うか...? usable = new LinkedList<Integer>(); map = new int[5][5]; Scanner scan = new Scanner(System.in); for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ map[i][j]=scan.nextInt(); usable.add(i*5+j+1); } } scan.close(); for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ if(map[i][j]!=0){ usable.remove(usable.indexOf(map[i][j])); } } } DFS(1); System.out.println(cnt); } static void DFS(int n){ int j=(n-1)%5; int i=(n-1)/5; if(map[i][j]!=0){ if(judge(i,j)){ if(n==25){ count(); return; } DFS(num(i,j)+1); }else{ return; } }else{ //MAPがもともと埋まっていない場合、usableから一つずつ出す int loop = usable.size(); for(int k=0;k<loop;k++){ int p=usable.poll(); map[i][j]=p; if(judge(i,j)){ if(n==25){ count(); map[i][j]=0; usable.add(p); return; } DFS(num(i,j)+1); map[i][j]=0; usable.add(p); }else{ map[i][j]=0; usable.add(p); } } return; } } static void count(){ cnt++; cnt%=INF; } static int num(int i,int j){ return(i*5+j+1); } static boolean judge(int i,int j){ //(i,j)マスにおいて条件を満たすか int[][] n=new int[2][3]; if(i<2&&j<2){ return true; }else if(i<2){ for(int k=0;k<3;k++){ n[0][k]=map[i][j-k]; } if((n[0][1]-n[0][0])*(n[0][1]-n[0][2])<0){return false;}else{return true;} }else if(j<2){ for(int k=0;k<3;k++){ n[1][k]=map[i-k][j]; } if((n[1][1]-n[1][0])*(n[1][1]-n[1][2])<0){return false;}else{return true;} }else{ for(int k=0;k<3;k++){ n[0][k]=map[i][j-k]; } for(int k=0;k<3;k++){ n[1][k]=map[i-k][j]; } if((n[0][1]-n[0][0])*(n[0][1]-n[0][2])<0||(n[1][1]-n[1][0])*(n[1][1]-n[1][2])<0){ return false; }else{ return true; } } } }
Submission Info
Submission Time | |
---|---|
Task | D - 25個の整数 |
User | inmir |
Language | Java8 (OpenJDK 1.8.0) |
Score | 30 |
Code Size | 2292 Byte |
Status | TLE |
Exec Time | 5264 ms |
Memory | 358872 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 | 109 ms | 19792 KB |
sample-02.txt | AC | 129 ms | 37572 KB |
sample-03.txt | AC | 94 ms | 21588 KB |
sample-04.txt | AC | 93 ms | 19540 KB |
test-1-01.txt | AC | 93 ms | 18900 KB |
test-1-02.txt | AC | 105 ms | 20052 KB |
test-1-03.txt | AC | 106 ms | 19028 KB |
test-1-04.txt | AC | 106 ms | 18772 KB |
test-1-05.txt | AC | 120 ms | 21204 KB |
test-1-06.txt | AC | 121 ms | 24648 KB |
test-1-07.txt | AC | 105 ms | 21844 KB |
test-1-08.txt | AC | 112 ms | 24532 KB |
test-1-09.txt | AC | 98 ms | 20688 KB |
test-1-10.txt | AC | 94 ms | 19924 KB |
test-1-11.txt | AC | 93 ms | 19796 KB |
test-1-12.txt | AC | 114 ms | 21588 KB |
test-1-13.txt | AC | 94 ms | 19028 KB |
test-1-14.txt | AC | 114 ms | 22728 KB |
test-1-15.txt | AC | 115 ms | 24648 KB |
test-2-01.txt | TLE | 5259 ms | 358352 KB |
test-2-02.txt | TLE | 5259 ms | 357220 KB |
test-2-03.txt | AC | 729 ms | 236108 KB |
test-2-04.txt | TLE | 5264 ms | 358324 KB |
test-2-05.txt | TLE | 5259 ms | 350936 KB |
test-2-06.txt | TLE | 5263 ms | 358872 KB |
test-2-07.txt | TLE | 5264 ms | 354700 KB |
test-2-08.txt | TLE | 5263 ms | 358340 KB |
test-2-09.txt | TLE | 5263 ms | 356540 KB |
test-2-10.txt | TLE | 5259 ms | 355624 KB |