結果
問題 |
No.561 東京と京都
|
ユーザー |
![]() |
提出日時 | 2017-08-27 17:32:09 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,266 bytes |
コンパイル時間 | 3,111 ms |
コンパイル使用メモリ | 77,552 KB |
実行使用メモリ | 509,640 KB |
最終ジャッジ日時 | 2024-11-06 06:50:41 |
合計ジャッジ時間 | 16,161 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 WA * 8 TLE * 3 |
ソースコード
package yukicoder; import java.util.Random; import java.util.Scanner; public class Main { private static int[] tokyo; private static int[] kyoto; private static int days; private static int exp; public static void main(String[] args) { // 自分の得意な言語で // Let's チャレンジ!! Scanner sc = new Scanner(System.in); days = sc.nextInt(); exp = sc.nextInt(); tokyo = new int[days]; kyoto = new int[days]; for(int i = 0 ; i < days ; i++){ tokyo[i] = sc.nextInt(); kyoto[i] = sc.nextInt(); } int gain = greed(); int gain2 = random(); int maxGain = gain > gain2 ? gain : gain2; System.out.println(maxGain); } private static int random() { int num = 10000*1000/days; int pow[][] = new int[num][days]; for(int i = 0 ; i < num ; i++){ for(int j = 0 ; j < days ; j++){ Random r = new Random((int)(Math.random()*1000)); pow[i][j] = r.nextInt(2); } } int gain = 0; int maxGain = 0; boolean tokyoto = true; for(int i = 0 ; i < num ; i++){ gain = 0; tokyoto = true; for(int j = 0 ; j < days ; j++){ if(pow[i][j] == 0){ if(tokyoto){ gain += tokyo[j]; }else{ gain += tokyo[j] - exp; tokyoto = true; } }else{ if(tokyoto){ gain += kyoto[j] - exp; tokyoto = false; }else{ gain += kyoto[j]; } } } maxGain = gain > maxGain ? gain : maxGain; } return maxGain; } private static int greed() { int gain = 0; boolean tokyoto = true; for(int i = 0 ; i < days ; i++){ if(tokyoto){ if(tokyo[i] >= (kyoto[i]-exp)){ gain += tokyo[i]; }else{ tokyoto = false; gain += kyoto[i] - exp; } }else{ if(kyoto[i] >= (tokyo[i]-exp)){ gain += kyoto[i]; }else{ tokyoto = true; gain += tokyo[i] - exp; } } } return gain; } }