結果

問題 No.813 ユキちゃんの冒険
ユーザー leaf_1415leaf_1415
提出日時 2019-04-16 02:27:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,097 bytes
コンパイル時間 2,235 ms
コンパイル使用メモリ 59,852 KB
実行使用メモリ 11,428 KB
最終ジャッジ日時 2023-08-30 15:16:37
合計ジャッジ時間 3,664 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 WA -
testcase_02 AC 5 ms
7,252 KB
testcase_03 WA -
testcase_04 AC 18 ms
11,428 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 16 ms
10,512 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 19 ms
11,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:27: warning: ‘max_j’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   double max_val = 0; int max_j;
                           ^~~~~

ソースコード

diff #

#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int n;
double p, q;
double mat[1005][1005];

void swap(int i, int j)
{
	for(int k = 1; k <= n+1; k++){
		double t = mat[i][k];
		mat[i][k] = mat[j][k];
		mat[j][k] = t;
	}
}

int main(void)
{
	cin >> n >> p >> q;
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i==j)  mat[i][j] = 1;
			if(i+1==j) mat[i][j] = -q;
			if(i==j+1) mat[i][j] = -p;
		}
	}
	mat[1][n+1] = p;
	
	for(int i = 1; i <= n; i++){
		double max_val = 0; int max_j;
		for(int j = i; j <= n; j++){
			if(fabs(mat[j][i]) > max_val){
				max_val = fabs(mat[j][i]);
				max_j = j;
			}
		}
		if(max_val < 1e-9){
			cout << "Non-Regular" << endl;
			return 0;
		}
		swap(i, max_j);
		
		double div = mat[i][i];
		for(int j = i; j <= i+1; j++) mat[i][j] /= div;
		mat[i][n+1] /= div;
		
		for(int j = 1; j <= i+1; j++){
			double coe = mat[j][i];
			if(i == j) continue;
			for(int k = i; k <= i+1; k++){
				mat[j][k] -= coe * mat[i][k];
			}
			mat[j][n+1] -= coe * mat[i][n+1];
		}
	}
	
	printf("%.11f\n", mat[1][n+1]);
	return 0;
}
0