結果

問題 No.74 貯金箱の退屈
ユーザー tnakao0123tnakao0123
提出日時 2016-03-06 19:32:40
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,865 bytes
コンパイル時間 913 ms
コンパイル使用メモリ 90,308 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2024-09-24 14:51:59
合計ジャッジ時間 11,259 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 5 TLE * 1 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 74.cc: No.74 貯金箱の退屈 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<bitset>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

typedef long long ll;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef bitset<MAX_N> bn;
typedef vector<bn> vbn;

/* global variables */

int n, ds[MAX_N];
bn wis, bms[MAX_N], gl;
vbn vbs[MAX_N];

/* subroutines */

void print_v(bn &v) {
  for (int i = 0; i < n; i++) printf("%d", v.test(i)); putchar('\n');
}

void print_m(bn (&m)[MAX_N]) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) printf("%d", m[i].test(j)); putchar('\n');
  }
}

void check(int u, bn ubs) {
  //printf("%d: ", u); print_v(ubs);
  if (ubs == gl) {
    puts("Yes");
    exit(0);
  }
  if (u >= n) return;
  
  if (ubs.test(u)) {
    vbn &uvb = vbs[u];
    for (vbn::iterator vit = uvb.begin(); vit != uvb.end(); vit++)
      check(u + 1, ubs ^ *vit);
  }

  check(u + 1, ubs);
}

/* main */

int main() {
  cin >> n;

  for (int i = 0; i < n; i++) cin >> ds[i];
  for (int i = 0; i < n; i++) {
    bool wi;
    cin >> wi;
    wis.set(i, ! wi);
  }

  for (int i = 0; i < n; i++) {
    int i0 = (i + ds[i]) % n;
    int i1 = i - ds[i];
    while (i1 < 0) i1 += n;
    bms[i].set(i0);
    bms[i].set(i1);
    vbs[min(i0, i1)].push_back(bms[i]);
  }
  //print_v(wis); print_m(bms);
  //for (int i = 0; i < n; i++) printf("%lu ", vbs[i].size()); putchar('\n');

  check(0, wis);
  puts("No");
  return 0;
}
0