結果

問題 No.74 貯金箱の退屈
ユーザー koba-e964koba-e964
提出日時 2015-06-08 18:28:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,439 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 67,112 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 19:54:20
合計ジャッジ時間 1,736 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <vector>


class GF2Matrix {
private:
  std::vector<std::vector<bool> > mat;
  int n, m;
public:
  GF2Matrix(int n, int m) : n(n), m(m), mat(n) {
    for (int i = 0; i < n; ++i) {
      mat[i] = std::vector<bool>(m);
    }
  }
  std::vector<bool> &operator[](int i) {
    return mat[i];
  }
  const std::vector<bool> &operator[](int i) const {
    return mat[i];
  }
  /* Returns the rank of this matrix. */
  int eliminate(void) {
    int r = 0;
    for (int c = 0; c < m; ++c) {
      int r1 = -1;
      for (int i = r; i < n; ++i) {
	if (mat[i][c]) {
	  r1 = i;
	  break;
	}
      }
      if (r1 == -1) {
	continue;
      }
      std::swap(mat[r], mat[r1]);
      for (int i = 0; i < n; ++i) {
	if (i != r && mat[i][c]) {
	  for (int j = c; j < m; ++j) {
	    mat[i][j] = mat[i][j] ^ mat[r][j];
	  }
	}
      }
      ++r;
    }
    return r;
  }
};
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#include <iostream>

using namespace std;

int main(void){
  int n;
  cin >> n;
  GF2Matrix mat(n, n + 1);
  REP(i, 0, n) {
    int d;
    cin >> d;
    int r1 = (i + d) % n;
    int r2 = (i - d % n + n) % n;
    mat[r1][i] = 1;
    mat[r2][i] = 1;
  }
  REP(i, 0, n) {
    int w;
    cin >> w;
    mat[i][n] = 1 - w;
  }
  int r = mat.eliminate();
  bool ok = 0;
  if (r >= 1) {
    REP(i, 0, n) {
      ok |= mat[r - 1][i];
    }
    ok |= !mat[r - 1][n];
  }
  cout << (ok ? "Yes" : "No") << endl;
}
0