結果

問題 No.2446 完全列
ユーザー SSRSSSRS
提出日時 2023-08-25 21:56:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,178 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 209,980 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 01:34:32
合計ジャッジ時間 2,927 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct frac{
  long long num, den;
  frac(){
  }
  frac(int x): num(x), den(1){
  }
  frac(long long x, long long y){
    long long g = gcd(x, y);
    num = x / g;
    den = y / g;
    if (den < 0){
      num *= -1;
      den *= -1;
    }
  }
  frac operator +(frac x){
    return frac(num * x.den + x.num * den, den * x.den);
  }
  frac operator -(frac x){
    return frac(num * x.den - x.num * den, den * x.den);
  }
  frac operator *(frac x){
    return frac(num * x.num, den * x.den);
  }
  frac operator /(frac x){
    return frac(num * x.den, den * x.num);
  }
};
int solve(vector<vector<int>> A){
  int N = A.size();
  int M = A[0].size();
  vector<vector<frac>> A2(N, vector<frac>(M));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      A2[i][j] = frac(A[i][j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i++){
    bool ok = false;
    for (int j = ans; j < N; j++){
      if (A2[j][i].num != 0){
        ok = true;
        swap(A2[ans], A2[j]);
        break;
      }
    }
    if (ok){
      int p = ans;
      frac x = frac(1) / A2[p][i];
      for (int j = i; j < M; j++){
        A2[p][j] = A2[p][j] * x;
      }
      for (int j = 0; j < N; j++){
        if (j != p){
          frac m = A2[j][i];
          for (int k = i; k < M; k++){
            A2[j][k] = A2[j][k] - m * A2[p][k];
          }
        }
      }
      ans++;
    }
  }
  return ans;
}
int main(){
  int L,  M, N;
  cin >> L >> M >> N;
  vector<vector<int>> A(L, vector<int>(M));
  for (int i = 0; i < L; i++){
    for (int j = 0; j < M; j++){
      cin >> A[i][j];
    }
  }
  vector<vector<int>> B(M, vector<int>(N));
  for (int i = 0; i < M; i++){
    for (int j = 0; j < N; j++){
      cin >> B[i][j];
    }
  }
  bool ok = true;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < L; j++){
      long long sum = 0;
      for (int k = 0; k < M; k++){
        sum += A[j][k] * B[k][i];
      }
      if (sum != 0){
        ok = false;
      }
    }
  }
  if (!ok){
    cout << "No" << endl;
  } else {
    if (solve(A) + solve(B) == M){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
0