結果

問題 No.43 野球の試合
ユーザー holegumaholeguma
提出日時 2015-08-11 04:12:09
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,568 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 75,008 KB
実行使用メモリ 52,924 KB
最終ジャッジ日時 2023-09-25 08:04:26
合計ジャッジ時間 3,544 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;

class Main{

static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE/2;

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

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()){
int n=Integer.parseInt(line);
int[][] res=new int[n][n];
int[] win=new int[n];
ArrayList<Pair> array=new ArrayList<Pair>();
for(int i=0;i<n;i++){
line=br.readLine();
for(int j=0;j<n;j++){
char c=line.charAt(j);
if(c=='#'||c=='x') res[i][j]=0;
if(c=='o'){
res[i][j]=1; win[i]++;
}
if(c=='-'){
res[i][j]=INF;
if(i>j&&j!=0) array.add(new Pair(i,j));
}
}
}
for(int i=0;i<n;i++){
if(res[0][i]==INF){
res[0][i]=1; res[i][0]=0;
win[0]++;
}
}
int ans=INF;
dfs(0,ans,res,win,array);
out.println(ans);
out.flush();
}
}

private static void dfs(int depth,int ans,int[][] res,int[] win,ArrayList<Pair> array){
if(depth==array.size()){
int r=checkRank(win);
ans=Math.min(ans,r);
}
Pair p=array.get(depth);
int x=p.x;
int y=p.y;
res[x][y]=1; res[y][x]=0;
win[x]++;
dfs(depth+1,ans,res,win,array);
win[x]--;
res[x][y]=0; res[y][x]=1;
win[y]++;
dfs(depth+1,ans,res,win,array);
}

private static int checkRank(int[] win){
int[] winc=win.clone();
int cnt=1;
int prev=0;
Arrays.sort(winc);
for(int i=winc.length-1;i>=0;i--){
if(win[0]<winc[i]){
cnt=(prev==winc[i])?cnt:cnt+1;
prev=winc[i];
}
else return cnt;
}
return -1;
}
}
0