結果

問題 No.968 引き算をして門松列(その3)
ユーザー 37zigen37zigen
提出日時 2019-12-29 14:23:21
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,725 bytes
コンパイル時間 2,370 ms
コンパイル使用メモリ 76,528 KB
実行使用メモリ 74,624 KB
最終ジャッジ日時 2023-08-05 18:43:59
合計ジャッジ時間 16,751 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
57,464 KB
testcase_01 AC 158 ms
57,708 KB
testcase_02 AC 204 ms
58,972 KB
testcase_03 AC 1,630 ms
65,756 KB
testcase_04 AC 1,198 ms
72,368 KB
testcase_05 AC 1,338 ms
74,624 KB
testcase_06 AC 1,155 ms
65,856 KB
testcase_07 AC 1,083 ms
64,668 KB
testcase_08 AC 1,455 ms
65,000 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.
import java.util.*;
import java.io.*;

class Main
{
    public static void main(String[] args)
    {
		new Main().run();
	}
	
	boolean check(long[] a){
		if(a[0]==a[1]||a[1]==a[2]||a[2]==a[0]||a[0]<=0||a[1]<=0||a[2]<=0)return false;
		return a[1]==Math.min(a[0],Math.min(a[1],a[2])) || a[1]==Math.max(a[0],Math.max(a[1],a[2]));
	}
	
	long solve(long[] a,long[] c){
//		if(a[0]>a[2]){
//			a[0]^=a[2];a[2]^=a[0];a[0]^=a[2];
//		}
		if(check(a))return 0;
		ArrayList<Long> list=new ArrayList<>();
		list.add(0L);
		for(int i=0;i<3;++i){
			for(int d=-2;d<=2;++d){
				if(a[i]+d>0)
					list.add(a[i]+d);
			}
		}
		for(int i=0;i<a.length;++i){
			for(int j=0;j<a.length;++j){
				for(int d=-2;d<=2;++d){
					if(a[i]-a[j]+d>0)
						list.add(a[i]-a[j]+d);
				}
			}
		}
		long ret=Long.MAX_VALUE/3;
		for(int i=0;i<list.size();++i){
			for(int j=0;j<list.size();++j){
				for(int k=0;k<list.size();++k){
					long u=list.get(i),v=list.get(j),w=list.get(k);
					if(check(new long[]{a[0]-u-w,a[1]-u-v,a[2]-v-w})){
						ret=Math.min(ret,c[0]*u+c[1]*v+c[2]*w);
					}
				}
			}
		}
		return ret>1e10?-1:ret;
	}
	
	void run(){
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);								
		int T=sc.nextInt();
		for(int t=0;t<T;++t){
			long[] a=new long[3];
			long[] c=new long[3];
			for(int i=0;i<3;++i)a[i]=sc.nextLong();
			for(int i=0;i<3;++i)c[i]=sc.nextLong();
			pw.println(solve(a,c));
		}
		pw.close();
	}
	
	void tr(Object...objects){
		System.out.println(Arrays.deepToString(objects));
	}
}

// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase
0