結果
| 問題 |
No.967 引き算をして門松列(その2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-22 04:30:30 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,286 bytes |
| コンパイル時間 | 3,180 ms |
| コンパイル使用メモリ | 77,820 KB |
| 実行使用メモリ | 59,848 KB |
| 最終ジャッジ日時 | 2024-12-24 13:34:11 |
| 合計ジャッジ時間 | 9,246 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 10 |
ソースコード
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));
}
}