結果

問題 No.74 貯金箱の退屈
ユーザー atetubouatetubou
提出日時 2014-11-21 09:17:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,333 bytes
コンパイル時間 2,979 ms
コンパイル使用メモリ 189,456 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 22:06:58
合計ジャッジ時間 3,972 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef ll li;
typedef pair<ll,ll> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
#define FORR(it,a) for(__typeof(a.rbegin())it=a.rbegin();it!=a.rend();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
#define declare(a,it) __typeof(a) it=a
const double EPS = 1e-8;

const int dx[]={1,0,-1,0,1,1,-1,-1,0};
const int dy[]={0,1,0,-1,-1,1,-1,1,0};

#define endl '\n'


typedef vector<int> arr;
typedef vector<arr> mat;

bool sol(mat A,arr y){//Ax=y, return x
  int n = A.size();
  mat B(n,arr(n));
  mat ab = A;
  for(int i = 0; i < n; ++i)
    B[i][i] = 1;
  
  for(int i = 0; i < n; ++i){
    for(int j=i+1;j < n; ++j){
      if(abs(A[j][i]) > abs(A[i][i])){
         swap(A[j],A[i]);
         swap(B[j],B[i]);
      }
    }
    
    for(int j = 0; j < n; ++j){
      if(i==j) continue;
      int m = A[j][i];
      for(int k = 0; k < n; ++k){
        A[j][k] -= A[i][k] * m;
        B[j][k] -= B[i][k] * m;
        A[j][k] &= 1;
        B[j][k] &= 1;
      }
    }
  }
  
  arr ret(n);
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j)
      ret[i] += B[i][j] * y[j];
  arr cy(n);
  rep(i,n)rep(j,n) (cy[i] += ab[i][j] * ret[j]) &= 1;
  
  return y == cy;
}

int main(int argc, char *argv[])
{
  int n;
  cin >> n;
  mat A(n,arr(n));
  
  rep(i,n){
    int d;
    cin >> d;
    A[(i+d)%n][i] = 1;
    //A[i][i] = 1;
    A[((i-d)%n+n)%n][i] = 1;
  }
  arr x(n);
  rep(i,n) cin >> x[i];
  rep(i,n) x[i] = 1 - x[i];
  cout << (sol(A,x)?"Yes":"No") << endl;
  /*
    0 1 0 0   1
    1 0 0 1 = 0
    1 1 0 1   0 
   */
}
0