結果

問題 No.90 品物の並び替え
ユーザー holegumaholeguma
提出日時 2015-08-17 20:35:49
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 911 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 74,228 KB
実行使用メモリ 51,652 KB
最終ジャッジ日時 2023-09-25 12:37:46
合計ジャッジ時間 3,218 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

class Main{

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

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line=br.readLine();
int n=Integer.parseInt(line.split(" ")[0]);
int m=Integer.parseInt(line.split(" ")[1]);
int[][] score=new int[n][n];
int[][] dp=new int[n*n+1][n*(n-1)/2+1];
Arrays.fill(dp[n*n],INF);
dp[n*n][0]=0;
while(m-->0){
line=br.readLine();
int a=Integer.parseInt(line.split(" ")[0]);
int b=Integer.parseInt(line.split(" ")[1]);
score[a][b]=Integer.parseInt(line.split(" ")[2]);
}
for(int i=n*n-1;i>=0;i--){
for(int j=0;j<=n*(n-1)/2;j++){
if(j==0||(int)i/n==i%n) dp[i][j]=dp[i+1][j];
else dp[i][j]=Math.max(dp[i+1][j],dp[i+1][j-1]+score[(int)i/n][i%n]);
}
}
out.println(dp[0][n*(n-1)/2]);
out.flush();
}
}
0