結果

問題 No.471 直列回転機
ユーザー uwiuwi
提出日時 2016-12-21 00:12:53
言語 Java21
(openjdk 21)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,486 bytes
コンパイル時間 3,657 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 82,720 KB
平均クエリ数 18780.53
最終ジャッジ日時 2024-07-16 11:30:27
合計ジャッジ時間 34,901 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
70,832 KB
testcase_01 RE -
testcase_02 AC 153 ms
71,296 KB
testcase_03 AC 164 ms
71,292 KB
testcase_04 AC 161 ms
71,264 KB
testcase_05 AC 211 ms
72,128 KB
testcase_06 AC 196 ms
70,716 KB
testcase_07 AC 199 ms
71,396 KB
testcase_08 AC 339 ms
76,420 KB
testcase_09 AC 344 ms
76,312 KB
testcase_10 AC 281 ms
76,632 KB
testcase_11 AC 520 ms
76,072 KB
testcase_12 AC 690 ms
80,764 KB
testcase_13 AC 671 ms
82,072 KB
testcase_14 AC 787 ms
78,960 KB
testcase_15 AC 764 ms
82,404 KB
testcase_16 AC 198 ms
71,328 KB
testcase_17 AC 151 ms
70,872 KB
testcase_18 AC 148 ms
70,860 KB
testcase_19 AC 156 ms
71,740 KB
testcase_20 AC 719 ms
80,824 KB
testcase_21 AC 391 ms
76,320 KB
testcase_22 AC 700 ms
79,048 KB
testcase_23 RE -
testcase_24 AC 537 ms
76,496 KB
testcase_25 AC 361 ms
76,460 KB
testcase_26 AC 726 ms
82,120 KB
testcase_27 AC 514 ms
76,336 KB
testcase_28 AC 584 ms
76,584 KB
testcase_29 AC 590 ms
79,144 KB
testcase_30 AC 413 ms
75,736 KB
testcase_31 AC 711 ms
79,956 KB
testcase_32 AC 680 ms
77,288 KB
testcase_33 AC 589 ms
77,108 KB
testcase_34 AC 708 ms
81,192 KB
testcase_35 AC 396 ms
76,240 KB
testcase_36 AC 482 ms
77,208 KB
testcase_37 AC 315 ms
76,608 KB
testcase_38 AC 383 ms
76,216 KB
testcase_39 AC 428 ms
75,912 KB
testcase_40 AC 641 ms
78,616 KB
testcase_41 AC 795 ms
81,596 KB
testcase_42 AC 581 ms
77,104 KB
testcase_43 AC 695 ms
82,720 KB
testcase_44 AC 274 ms
75,764 KB
testcase_45 AC 565 ms
79,172 KB
testcase_46 AC 621 ms
78,280 KB
testcase_47 AC 677 ms
82,156 KB
testcase_48 AC 710 ms
77,448 KB
testcase_49 AC 647 ms
77,492 KB
testcase_50 AC 747 ms
81,476 KB
testcase_51 AC 494 ms
77,380 KB
testcase_52 AC 203 ms
71,488 KB
testcase_53 AC 211 ms
71,368 KB
testcase_54 AC 235 ms
72,412 KB
testcase_55 AC 415 ms
76,104 KB
testcase_56 RE -
testcase_57 AC 331 ms
76,884 KB
testcase_58 AC 300 ms
76,148 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(20)-10;
			ys[i] = gen.nextInt(20)-10;
			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