結果

問題 No.561 東京と京都
ユーザー Amanita2016Amanita2016
提出日時 2017-08-27 17:32:09
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,266 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 77,264 KB
実行使用メモリ 492,952 KB
最終ジャッジ日時 2024-04-24 00:19:30
合計ジャッジ時間 29,226 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,555 ms
272,904 KB
testcase_01 AC 1,607 ms
273,188 KB
testcase_02 AC 1,569 ms
273,272 KB
testcase_03 AC 1,351 ms
240,260 KB
testcase_04 AC 1,053 ms
173,276 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 AC 1,002 ms
165,500 KB
testcase_09 WA -
testcase_10 AC 877 ms
138,004 KB
testcase_11 WA -
testcase_12 AC 713 ms
102,936 KB
testcase_13 AC 714 ms
103,252 KB
testcase_14 AC 741 ms
102,276 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
	}
}
0