結果
問題 |
No.90 品物の並び替え
|
ユーザー |
![]() |
提出日時 | 2015-08-17 20:35:49 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 911 bytes |
コンパイル時間 | 2,206 ms |
コンパイル使用メモリ | 77,908 KB |
実行使用メモリ | 52,536 KB |
最終ジャッジ日時 | 2024-07-18 10:03:01 |
合計ジャッジ時間 | 2,834 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 9 |
ソースコード
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(); } }