結果

問題 No.967 引き算をして門松列(その2)
ユーザー 37zigen37zigen
提出日時 2020-03-22 04:30:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,286 bytes
コンパイル時間 3,260 ms
コンパイル使用メモリ 74,344 KB
実行使用メモリ 61,816 KB
最終ジャッジ日時 2023-08-26 01:00:23
合計ジャッジ時間 7,186 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}
	
	long solve(long A,long B,long C,long X,long Y,long Z) {
		final long INF=Long.MAX_VALUE/3;
		long ret=INF,base=0;
		if(A==C) {
			--A;
			base+=X;
			if(A==0)return -1;
		}
		
		// A < C
		// B is min
		{
			if(A-1>0)ret=Math.min(ret,base+Y*Math.max(0,(B-(A-1))));
		}
		// A < C		
		// B is max
		{
			long cost=Math.max(0, A-(B-1))*X+Math.max(0, C-(B-1))*Z;
			A=Math.min(A, B-1);
			C=Math.min(C, B-1);
			if(A==C) {
				--A;
				cost+=X;
			}	
			if(A>0)ret=Math.min(ret, cost+base);
		}
		return ret==INF?-1:ret;
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int T=sc.nextInt();
		for(int t=0;t<T;++t) {
			long A=sc.nextLong();
			long B=sc.nextLong();
			long C=sc.nextLong();
			long X=sc.nextLong();
			long Y=sc.nextLong();
			long Z=sc.nextLong();
			if(A>C||(A==C&&X>Z)) {
				A^=C;C^=A;A^=C;X^=Z;Z^=X;X^=Z;
			}
			System.out.println(solve(A,B,C,X,Y,Z));
		}
	}


	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0