結果

問題 No.561 東京と京都
ユーザー Amanita2016Amanita2016
提出日時 2017-08-27 17:33:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,264 bytes
コンパイル時間 2,448 ms
コンパイル使用メモリ 77,560 KB
実行使用メモリ 47,912 KB
最終ジャッジ日時 2024-04-24 00:20:43
合計ジャッジ時間 7,239 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
45,912 KB
testcase_01 AC 172 ms
46,040 KB
testcase_02 AC 168 ms
46,528 KB
testcase_03 AC 187 ms
46,192 KB
testcase_04 AC 164 ms
45,408 KB
testcase_05 AC 185 ms
47,888 KB
testcase_06 AC 186 ms
47,696 KB
testcase_07 AC 179 ms
47,912 KB
testcase_08 AC 175 ms
46,048 KB
testcase_09 WA -
testcase_10 AC 169 ms
45,944 KB
testcase_11 WA -
testcase_12 AC 174 ms
45,912 KB
testcase_13 AC 176 ms
45,860 KB
testcase_14 AC 175 ms
45,984 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 = 100*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