結果

問題 No.2405 Minimal Matrix Decomposition
ユーザー 👑 獅子座じゃない人獅子座じゃない人
提出日時 2023-07-28 13:42:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,568 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 174,084 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 22:48:38
合計ジャッジ時間 7,345 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 AC 45 ms
6,944 KB
testcase_05 AC 184 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 95 ms
6,944 KB
testcase_11 AC 119 ms
6,944 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 32 ms
6,940 KB
testcase_14 AC 28 ms
6,940 KB
testcase_15 AC 12 ms
6,940 KB
testcase_16 AC 13 ms
6,940 KB
testcase_17 AC 53 ms
6,940 KB
testcase_18 AC 33 ms
6,944 KB
testcase_19 AC 31 ms
6,940 KB
testcase_20 AC 5 ms
6,940 KB
testcase_21 AC 8 ms
6,944 KB
testcase_22 AC 97 ms
6,944 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 7 ms
6,940 KB
testcase_26 AC 68 ms
6,944 KB
testcase_27 AC 26 ms
6,940 KB
testcase_28 AC 56 ms
6,944 KB
testcase_29 AC 17 ms
6,940 KB
testcase_30 AC 80 ms
6,940 KB
testcase_31 AC 34 ms
6,944 KB
testcase_32 AC 8 ms
6,940 KB
testcase_33 AC 63 ms
6,940 KB
testcase_34 AC 17 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 30 ms
6,944 KB
testcase_37 AC 42 ms
6,940 KB
testcase_38 AC 39 ms
6,944 KB
testcase_39 AC 64 ms
6,940 KB
testcase_40 AC 40 ms
6,944 KB
testcase_41 AC 7 ms
6,944 KB
testcase_42 AC 84 ms
6,940 KB
testcase_43 AC 27 ms
6,940 KB
testcase_44 AC 20 ms
6,944 KB
testcase_45 AC 8 ms
6,944 KB
testcase_46 AC 18 ms
6,944 KB
testcase_47 AC 23 ms
6,940 KB
testcase_48 AC 10 ms
6,944 KB
testcase_49 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/modint>
using namespace atcoder;
using mint=modint;

int main(void)
{
    int p;
    cin >> p;
    int n,m;
    cin >> n >> m;
    mint::set_mod(p);
    vector<vector<mint>> a(n,vector<mint>(m));
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            int atmp;
            cin >> atmp;
            a[i][j]=atmp;
        }
    }
    vector<vector<mint>> a_copy=a;
    int rank=0;
    for(int i=0;i<m;++i){
        if(rank==n){
            break;
        }
        if(a_copy[rank][i]==0){
            bool not_pivot=true;
            for(int j=rank+1;j<n;++j){
                if(a_copy[j][i]!=0){
                    not_pivot=false;
                    for(int k=i;k<m;++k){
                        swap(a_copy[rank][k],a_copy[j][k]);
                    }
                    break;
                }
            }
            if(not_pivot){
                continue;
            }
        }
        for(int j=m-1;j>=i;--j){
            a_copy[rank][j]/=a_copy[rank][i];
        }
        for(int j=0;j<n;++j){
            if(j==rank){
                continue;
            }
            for(int k=m-1;k>=i;--k){
                a_copy[j][k]-=a_copy[rank][k]*a_copy[j][i];
            }
        }
        ++rank;
    }
    if(n*m<=n*rank+rank*m){
        cout << 1 << endl;
        cout << n << " " << m << endl;
        for(int i=0;i<n;++i){
            for(int j=0;j<m;++j){
                cout << a[i][j].val() << " ";
            }
            cout << endl;
        }
    } else {
        vector<vector<mint>> c(n,vector<mint>(rank));
        int pivot=0;
        for(int i=0;i<m;++i){
            if(pivot==n){
                break;
            }
            if(a_copy[pivot][i]==0){
                continue;
            }
            for(int j=0;j<n;++j){
                c[j][pivot]=a[j][i];
            }
            ++pivot;
        }
        vector<vector<mint>> f(rank,vector<mint>(m));
        for(int i=0;i<rank;++i){
            for(int j=0;j<m;++j){
                f[i][j]=a_copy[i][j];
            }
        }
        cout << 2 << endl;
        cout << n << " " << rank << endl;
        for(int i=0;i<n;++i){
            for(int j=0;j<rank;++j){
                cout << c[i][j].val() << " ";
            }
            cout << endl;
        }
        cout << rank << " " << m << endl;
        for(int i=0;i<rank;++i){
            for(int j=0;j<m;++j){
                cout << f[i][j].val() << " ";
            }
            cout << endl;
        }
    }
    return 0;
}
0