結果

問題 No.328 きれいな連立方程式
ユーザー 37zigen37zigen
提出日時 2016-05-02 20:16:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 4,070 bytes
コンパイル時間 2,739 ms
コンパイル使用メモリ 83,628 KB
実行使用メモリ 42,060 KB
最終ジャッジ日時 2024-04-15 09:19:12
合計ジャッジ時間 8,774 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
41,928 KB
testcase_01 AC 146 ms
41,896 KB
testcase_02 AC 145 ms
41,876 KB
testcase_03 AC 144 ms
41,652 KB
testcase_04 AC 147 ms
41,472 KB
testcase_05 AC 146 ms
41,668 KB
testcase_06 AC 152 ms
41,644 KB
testcase_07 AC 147 ms
41,792 KB
testcase_08 AC 148 ms
41,832 KB
testcase_09 AC 149 ms
42,052 KB
testcase_10 AC 151 ms
41,780 KB
testcase_11 AC 149 ms
41,880 KB
testcase_12 AC 147 ms
42,060 KB
testcase_13 AC 147 ms
41,544 KB
testcase_14 AC 147 ms
41,724 KB
testcase_15 AC 146 ms
41,748 KB
testcase_16 AC 154 ms
41,768 KB
testcase_17 AC 147 ms
41,536 KB
testcase_18 AC 149 ms
41,776 KB
testcase_19 AC 147 ms
41,768 KB
testcase_20 AC 146 ms
41,932 KB
testcase_21 AC 150 ms
41,636 KB
testcase_22 AC 150 ms
41,692 KB
testcase_23 AC 147 ms
41,396 KB
testcase_24 AC 145 ms
41,548 KB
testcase_25 AC 148 ms
41,572 KB
testcase_26 AC 147 ms
41,812 KB
testcase_27 AC 145 ms
41,404 KB
testcase_28 AC 150 ms
42,040 KB
testcase_29 AC 149 ms
41,784 KB
testcase_30 AC 151 ms
41,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		double c1=sc.nextDouble();
		double c2=sc.nextDouble();
		double c3=sc.nextDouble();
		double c4=sc.nextDouble();
		double[][] v1={{c3},{c4}};
		double[][] A={{c2,-c1},{c3,-c2}};
		double[][] v2=MtPrd(ReMt(A),v1);
		double a=v2[0][0];
		double b=v2[1][0];
		if(a*a-4*b>=0){
			System.out.println("R");
		}else{
			System.out.println("I");
		}
	}
	//行列の引き算 A-B
	double[][] MtSbtr(double[][] A,double[][] B){
		return MtSum(A,Mtce(-1,B));
	}
	//行列の定数倍 kA
	double[][] Mtce(double k,double[][] A){
		double[][] B=new double[A.length][A[0].length];
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				B[i][j]=k*A[i][j];
			}
		}
		return B;
	}
	//転置行列(transposed matrix)
	double[][] TpMt(double[][] A){
		double[][] B=new double[A[0].length][A.length];
		for(int i=0;i<A[0].length;i++){
			for(int j=0;j<A.length;j++){
				B[i][j]=A[j][i];
			}
		}
		return B;
	}
	//ABC
	double[][] MtPrd(double[][] A,double[][] B,double[][] C){
		return MtPrd(MtPrd(A,B),C);
	}
	//ABCD
	double[][] MtPrd(double[][] A,double[][] B,double[][] C,double[][] D){
		return MtPrd(MtPrd(A,B,C),D);
	}
	//AB
	double[][] MtPrd(double[][] A,double[][] B){
		double[][] C=new double[A.length][B[0].length];
		for(int i=0;i<A.length;i++){
			for(int j=0;j<B[0].length;j++){
				for(int k=0;k<A[0].length;k++){
					C[i][j]+=A[i][k]*B[k][j];
				}
			}
		}
		return C;
	}
	long[][] MtPrd(long[][] A,long[][] B){
		long[][] C=new long[A.length][B[0].length];
		for(int i=0;i<A.length;i++){
			for(int j=0;j<B[0].length;j++){
				for(int k=0;k<A[0].length;k++){
					C[i][j]+=A[i][k]*B[k][j];
				}
			}
		}
		return C;
	}
	//行列の和;A+B
	double[][] MtSum(double[][] A,double[][] B){
		double[][] C=new double[A.length][A[0].length];
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				C[i][j]=A[i][j]+B[i][j];
			}
		}
		return C;
	}
	//2進数に変換;convert to binary
	BigInteger bi(int n){
		BigInteger b=new BigInteger("0");
		BigInteger digit=new BigInteger("10");
		for(int i=0;n!=0;i++){
			if(n%2==0){
				n/=2;
			}else{
				n-=1;
				n/=2;
				b=b.add(digit.pow(i));
			}
		}
		return b;
	}
	//行列のN乗;R=A^n
	long[][] MtPow(int n,long[][] A){
		BigInteger b=new BigInteger("0");
		b=bi(n);
		long[][] B=new long[A.length][A[0].length];
		for(int i=0;i<A.length;i++){
			B[i][i]=1;
		}
		while(b.compareTo(BigInteger.valueOf(1))>=0){
			if((b.remainder(BigInteger.valueOf(10)).compareTo(BigInteger.valueOf(1)))==0){
				B=MtPrd(A,B);
				b=b.subtract(BigInteger.valueOf(1));
				b=b.divide(BigInteger.valueOf(10));
			}else if((b.remainder(BigInteger.valueOf(10)).compareTo(BigInteger.valueOf(1)))!=0){
				b=b.divide(BigInteger.valueOf(10));
			}
			A=MtPrd(A,A);
		}
		return B;
	}
	//行列式;detA(Aが正方行列であることを仮定)
	double detMt(double[][] A){
		double sum=0;
		if(A.length==1||A[0].length==1){
			return A[0][0];
		}else{
			for(int j=0;j<A.length;j++){
				sum+=Math.pow(-1, j)*A[j][0]*detMt(subMt(j+1,0+1,A));
			}
			return sum;
		}
	}
	//i行、j列を除いた小行列を出力
	double[][] subMt(int i,int j,double[][] A){
		double[][] B=new double[A[0].length-1][A.length-1];
		for(int k=0;k<A[0].length-1;k++){
			for(int l=0;l<A.length-1;l++){
				int kk=k;
				int ll=l;
				if(k>=i-1){
					kk++ ;
				}
				if(l>=j-1){
					ll++;
				}
				B[k][l]=A[kk][ll];
			}
		}
		return B;
	}
	void showMt(double[][] A){
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				System.out.print(A[i][j]+" ");
			}
			System.out.println();
		}
	}
	//逆行列を求める。
	double[][] ReMt(double[][] A){
		double[][] B=new double[A.length][A[0].length];
		double detA=detMt(A);
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				B[i][j]=Math.pow(-1,i+j)*detMt(subMt(j+1,i+1,A))/detA;
			}
		}
		return B;
	}
}
0