結果
問題 |
No.970 数列変換マシン
|
ユーザー |
![]() |
提出日時 | 2020-01-17 23:37:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,104 bytes |
コンパイル時間 | 2,511 ms |
コンパイル使用メモリ | 199,300 KB |
最終ジャッジ日時 | 2025-01-08 19:22:41 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 9 WA * 1 TLE * 3 MLE * 9 |
ソースコード
#include<bits/stdc++.h> using namespace std; int select(vector<vector<double>> const& mat,size_t j){ size_t n = mat.size(); for(size_t i=j;i<n;++i){ if(mat[i][j]!=0)return i; } return -1; } void calc(vector<vector<double>>& mat,vector<double>& b,int base){ size_t n = mat.size(); double c = mat[base][base]; for(size_t i=base;i<n;++i){ mat[base][i] /= c; } b[base] /= c; for(size_t i=0;i<n;++i){ if(i==base)continue; double num = mat[i][base]; for(size_t j=0;j<n;++j){ mat[i][j] -= mat[base][j]*num; } b[i] -= b[base]*num; } } vector<double> solve(vector<vector<double>> mat,vector<double> b){ size_t n = mat.size(); for(size_t i=0;i<n;++i){ int base = select(mat,i); if(base==-1)continue; swap(mat[i],mat[base]); swap(b[i],b[base]); calc(mat,b,i); } return b; } signed main(){ int n; cin>>n; vector<vector<double>> mat(n,vector<double>(n,1)); for(int i=0;i<n;++i)mat[i][i]=0; vector<double> y(n); for(auto& yi:y)cin>>yi; auto res = solve(mat,y); for(auto r:res)cout<<r*(n-1)<<" ";cout<<endl; }