結果

問題 No.2405 Minimal Matrix Decomposition
ユーザー 👑 amentorimaruamentorimaru
提出日時 2023-07-29 18:52:40
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 1,766 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 127,144 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-16 23:38:59
合計ジャッジ時間 7,928 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 40 ms
5,376 KB
testcase_05 AC 211 ms
6,400 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 95 ms
5,376 KB
testcase_11 AC 122 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 27 ms
5,376 KB
testcase_14 AC 31 ms
5,376 KB
testcase_15 AC 11 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 55 ms
5,376 KB
testcase_18 AC 38 ms
5,376 KB
testcase_19 AC 39 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 8 ms
5,376 KB
testcase_22 AC 96 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 8 ms
5,376 KB
testcase_26 AC 75 ms
5,376 KB
testcase_27 AC 26 ms
5,376 KB
testcase_28 AC 71 ms
5,376 KB
testcase_29 AC 22 ms
5,376 KB
testcase_30 AC 85 ms
5,376 KB
testcase_31 AC 36 ms
5,376 KB
testcase_32 AC 6 ms
5,376 KB
testcase_33 AC 64 ms
5,376 KB
testcase_34 AC 16 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 27 ms
5,376 KB
testcase_37 AC 42 ms
5,376 KB
testcase_38 AC 49 ms
5,376 KB
testcase_39 AC 78 ms
5,376 KB
testcase_40 AC 36 ms
5,376 KB
testcase_41 AC 5 ms
5,376 KB
testcase_42 AC 85 ms
5,376 KB
testcase_43 AC 22 ms
5,376 KB
testcase_44 AC 21 ms
5,376 KB
testcase_45 AC 10 ms
5,376 KB
testcase_46 AC 21 ms
5,376 KB
testcase_47 AC 25 ms
5,376 KB
testcase_48 AC 10 ms
5,376 KB
testcase_49 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <unordered_set>
#include <atcoder/modint.hpp>

using namespace std;
using namespace atcoder;
using ll = long long;

int main() {
  ll p, n, m;
  cin >> p >> n >> m;
  modint::set_mod(p);
  vector a(n, vector<modint>(m));
  vector ba(n, vector<modint>(m));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      ll ta;
      cin >> ta;
      a[i][j] = ba[i][j] = ta;
    }
  }
  vector<vector<modint>> c(n);
  vector<vector<modint>> f;
  for (ll j = 0; j < m; j++) {
    ll ib = -1;
    for (ll i = 0; i < n; i++) {
      if (a[i][j] != 0) {
        ib = i;
        break;
      }
    }
    if (ib < 0)
      continue;
    f.push_back(a[ib]);
    for (ll i = 0; i < n; i++) {
      if (i == ib)
        continue;
      modint mul = a[i][j] / a[ib][j];
      c[i].push_back(mul);
      for (ll jj = j; jj < m; jj++) {
        a[i][jj] -= mul * a[ib][jj];
      }
    }
    c[ib].push_back(1);
    a[ib].assign(m, 0);
  }
  ll r = f.size();
  if (r == 0) {
    for (ll i = 0; i < n; i++) {
      c[i].push_back(0);
    }
    f.resize(1);
    f[0].assign(m, 0);
    r = 1;
  }
  if (n * m > (n + m) * r) {
    cout << 2 << endl;
    cout << n << " " << r << endl;
    for (ll i = 0; i < n; i++) {
      for (ll j = 0; j < r; j++) {
        cout << c[i][j].val() << " ";
      }
      cout << endl;
    }
    cout << r << " " << m << endl;
    for (ll i = 0; i < r; i++) {
      for (ll j = 0; j < m; j++) {
        cout << f[i][j].val() << " ";
      }
      cout << endl;
    }
  }
  else {
    cout << 1 << endl;
    cout << n << " " << m << endl;
    for (ll i = 0; i < n; i++) {
      for (ll j = 0; j < m; j++) {
        cout << ba[i][j].val() << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
0