結果

問題 No.85 TVザッピング(1)
ユーザー holegumaholeguma
提出日時 2015-08-14 17:26:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,103 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 75,072 KB
実行使用メモリ 52,532 KB
最終ジャッジ日時 2023-09-25 11:43:11
合計ジャッジ時間 4,831 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,548 KB
testcase_01 AC 45 ms
49,540 KB
testcase_02 AC 45 ms
49,452 KB
testcase_03 AC 45 ms
49,460 KB
testcase_04 AC 48 ms
52,260 KB
testcase_05 AC 46 ms
49,468 KB
testcase_06 AC 46 ms
49,764 KB
testcase_07 AC 44 ms
49,436 KB
testcase_08 AC 46 ms
49,688 KB
testcase_09 AC 45 ms
47,552 KB
testcase_10 WA -
testcase_11 AC 46 ms
49,404 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 45 ms
49,268 KB
testcase_15 WA -
testcase_16 AC 44 ms
49,364 KB
testcase_17 AC 45 ms
49,652 KB
testcase_18 AC 45 ms
49,600 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 46 ms
49,400 KB
testcase_22 AC 48 ms
50,620 KB
testcase_23 AC 47 ms
50,540 KB
testcase_24 WA -
testcase_25 AC 45 ms
49,776 KB
testcase_26 AC 46 ms
49,436 KB
testcase_27 WA -
testcase_28 AC 50 ms
52,084 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.StringTokenizer;


class Main{

static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE/2;
static int[] dx={-1,0,1,0};
static int[] dy={0,-1,0,1};

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
StringTokenizer st=new StringTokenizer(line);
int n=Integer.parseInt(st.nextToken());
int m=Integer.parseInt(st.nextToken());
int c=Integer.parseInt(st.nextToken());
boolean[][] visited=new boolean[n][m];
if(dfs(c%m==0?c/m-1:c/m,c%m==0?m-1:c%m-1,visited,c,n,m)) out.println("YES");
else out.println("NO");
out.flush();
}
}

private static boolean dfs(int a,int b,boolean[][] visited,int c,int n,int m){
if(m*a+b+1==c&&visited[a][b]){
if(check(visited,n,m)) return true;
else return false;
}
visited[a][b]=true;
for(int i=0;i<4;i++){
int na=a+dx[i];
int nb=b+dy[i];
if(na>=0&&nb>=0&&na<n&&nb<m&&(!visited[na][nb]||m*na+nb+1==c)){
if(dfs(na,nb,visited,c,n,m)) return true;
}
}
return false;
}

private static boolean check(boolean[][] visited,int n,int m){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(!visited[i][j]) return false;
}
}
return true;
}

static class Pair{
int x;
int y;
Pair(int x,int y){
this.x=x; this.y=y;
}
}

static class Edge{
int from;
int to;
int cost;
Edge(int from,int to,int cost){
this.from=from; this.to=to; this.cost=cost;
}
Edge(int to,int cost){
this.to=to; this.cost=cost;
}
}

static class Node{
int d;
int v;
Node(int d,int v){
this.d=d; this.v=v;
}
final static Comparator<Node> DISTANCE_ORDER=new DistanceOrderComparator();
static class DistanceOrderComparator implements Comparator<Node>{
public int compare(Node n1,Node n2){
return (n1.d>n2.d)?1:(n1.d<n2.d)?-1:0;
}
}
}
}
0