結果

問題 No.471 直列回転機
ユーザー uwiuwi
提出日時 2016-12-21 00:12:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 782 ms / 3,141 ms
コード長 3,488 bytes
コンパイル時間 3,982 ms
コンパイル使用メモリ 89,412 KB
実行使用メモリ 70,872 KB
平均クエリ数 19589.39
最終ジャッジ日時 2024-06-11 10:18:15
合計ジャッジ時間 33,432 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
58,720 KB
testcase_01 AC 143 ms
58,932 KB
testcase_02 AC 146 ms
58,348 KB
testcase_03 AC 140 ms
58,164 KB
testcase_04 AC 145 ms
58,332 KB
testcase_05 AC 205 ms
59,512 KB
testcase_06 AC 182 ms
58,352 KB
testcase_07 AC 192 ms
59,780 KB
testcase_08 AC 319 ms
64,308 KB
testcase_09 AC 315 ms
64,332 KB
testcase_10 AC 263 ms
64,708 KB
testcase_11 AC 488 ms
66,244 KB
testcase_12 AC 683 ms
68,372 KB
testcase_13 AC 708 ms
67,644 KB
testcase_14 AC 722 ms
68,116 KB
testcase_15 AC 782 ms
70,872 KB
testcase_16 AC 196 ms
59,104 KB
testcase_17 AC 141 ms
58,704 KB
testcase_18 AC 141 ms
58,812 KB
testcase_19 AC 149 ms
59,028 KB
testcase_20 AC 741 ms
70,572 KB
testcase_21 AC 383 ms
65,024 KB
testcase_22 AC 685 ms
68,136 KB
testcase_23 AC 616 ms
70,564 KB
testcase_24 AC 517 ms
66,804 KB
testcase_25 AC 350 ms
64,568 KB
testcase_26 AC 681 ms
67,900 KB
testcase_27 AC 508 ms
66,612 KB
testcase_28 AC 565 ms
67,692 KB
testcase_29 AC 571 ms
66,892 KB
testcase_30 AC 408 ms
65,804 KB
testcase_31 AC 678 ms
70,860 KB
testcase_32 AC 644 ms
67,416 KB
testcase_33 AC 606 ms
67,808 KB
testcase_34 AC 766 ms
68,080 KB
testcase_35 AC 362 ms
65,136 KB
testcase_36 AC 459 ms
65,544 KB
testcase_37 AC 302 ms
65,048 KB
testcase_38 AC 366 ms
64,688 KB
testcase_39 AC 417 ms
65,500 KB
testcase_40 AC 582 ms
67,728 KB
testcase_41 AC 751 ms
70,332 KB
testcase_42 AC 599 ms
69,508 KB
testcase_43 AC 649 ms
67,956 KB
testcase_44 AC 274 ms
63,256 KB
testcase_45 AC 558 ms
67,424 KB
testcase_46 AC 644 ms
67,632 KB
testcase_47 AC 713 ms
69,680 KB
testcase_48 AC 643 ms
70,288 KB
testcase_49 AC 605 ms
67,952 KB
testcase_50 AC 663 ms
70,720 KB
testcase_51 AC 453 ms
65,796 KB
testcase_52 AC 197 ms
59,408 KB
testcase_53 AC 191 ms
58,832 KB
testcase_54 AC 207 ms
59,944 KB
testcase_55 AC 396 ms
65,528 KB
testcase_56 AC 353 ms
64,552 KB
testcase_57 AC 300 ms
64,016 KB
testcase_58 AC 276 ms
63,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package adv2016;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class N471 {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static long[] get(long x, long y)
	{
		out.println("? " + x + " " + y);
		out.flush();
		return new long[]{nl(), nl()};
	}
	
	static void solve()
	{
		int m = ni();
		double[][] rotr = new double[m][];
		for(int i = 0;i < m;i++){
			rotr[i] = new double[]{ni(), ni(), 1};
		}
		Random gen = new Random();
		long[][] res = new long[3][];
		long[] xs = new long[3];
		long[] ys = new long[3];
		for(int i = 0;i < 3;i++){
			xs[i] = gen.nextInt(100)-50;
			ys[i] = gen.nextInt(100)-50;
			res[i] = get(xs[i], ys[i]);
			// ax+by+c=x'
		}
		double[][] X = new double[3][];
		{
			double[][] M = new double[3][3];
			double[] v = new double[3];
			for(int i = 0;i < 3;i++){
				M[i][0] = xs[i];
				M[i][1] = ys[i];
				M[i][2] = 1;
				v[i] = res[i][0];
			}
			double[] ret = solve(M, v);
			X[0] = ret;
		}
		{
			double[][] M = new double[3][3];
			double[] v = new double[3];
			for(int i = 0;i < 3;i++){
				M[i][0] = xs[i];
				M[i][1] = ys[i];
				M[i][2] = 1;
				v[i] = res[i][1];
			}
			double[] ret = solve(M, v);
			X[1] = ret;
		}
		{
			double[][] M = new double[3][3];
			double[] v = new double[3];
			for(int i = 0;i < 3;i++){
				M[i][0] = xs[i];
				M[i][1] = ys[i];
				M[i][2] = 1;
				v[i] = 1;
			}
			double[] ret = solve(M, v);
			X[2] = ret;
		}
		
		// (a b c) (x)
		// (d e f) (y)
		// (g h i) (1)
		
		out.println("!");
		for(int i = 0;i < m;i++){
			double[] w = mul(X, rotr[i]);
			out.println(Math.round(w[0]) + " " + Math.round(w[1]));
		}
	}
	
	public static double[] mul(double[][] A, double[] v)
	{
		int m = A.length;
		int n = v.length;
		double[] w = new double[m];
		for(int i = 0;i < m;i++){
			double sum = 0;
			for(int k = 0;k < n;k++){
				sum += A[i][k] * v[k];
			}
			w[i] = sum;
		}
		return w;
	}
	
	public static double[] solve(double[][] a, double[] c)
	{
		int n = a.length;
		int[] ps = new int[n];
		for(int i = 0;i < n;i++)ps[i] = i;
		
		// Forward Elimination
		for(int i = 0;i < n;i++){
			int pivot = -1;
			int from = -1;
			double amax = 0;
			for(int j = i;j < n;j++){
				if(Math.abs(a[ps[j]][i]) > amax){
					amax = Math.abs(a[ps[j]][i]);
					pivot = ps[j];
					from = j;
				}
			}
			if(pivot == -1)return null;
			int d = ps[i]; ps[i] = ps[from]; ps[from] = d;
			
			for(int j = i+1;j < n;j++){
				a[ps[i]][j] /= a[ps[i]][i];
			}
			c[ps[i]] /= a[ps[i]][i];
			a[ps[i]][i] = 1.0;
			for(int j = i+1;j < n;j++){
				for(int k = i+1;k < n;k++){
					a[ps[j]][k] -= a[ps[j]][i] * a[ps[i]][k];
				}
				c[ps[j]] -= a[ps[j]][i] * c[ps[i]];
				a[ps[j]][i] = 0.0;
			}
			
		}
		
		// Back Substitution
		for(int i = n-1;i >= 0;i--){
			for(int j = i-1;j >= 0;j--){
				c[ps[j]] -= a[ps[j]][i] * c[ps[i]];
			}
		}
		
		double[] ret = new double[n];
		for(int i = 0;i < n;i++){
			ret[i] = c[ps[i]];
		}
		
		return ret;
	}

	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
0