結果

問題 No.74 貯金箱の退屈
ユーザー tnakao0123tnakao0123
提出日時 2016-03-06 19:32:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,865 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 90,176 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 20:09:24
合計ジャッジ時間 12,148 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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