結果

問題 No.3 ビットすごろく
ユーザー cimjnuqycimjnuqy
提出日時 2016-04-18 18:22:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,863 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 70,480 KB
実行使用メモリ 10,656 KB
最終ジャッジ日時 2024-04-15 03:34:30
合計ジャッジ時間 8,105 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 688 ms
6,944 KB
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 #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

//難しい・・・

int main() {
  int n;
  cin >> n;

  vector<int> road;
  road.push_back(0);
  road.push_back(1);

  int max = -1;
  while (road.size() < n + 1) {
    int m = road.size();
    for (int i = 0; i < m; i++) {
      if (road.size() == n + 1) {
        break;
      }
      road.push_back(road[i] + 1);
      if (road[i] + 1 > max) {
        max = road[i] + 1;
      }
    }
  }

  vector<int> moves;

  for (int x = 0; x < max; x++) {
  
    vector<vector <int> > ways;
    vector<int> way;

    ways.clear();
    way.clear();
    way.push_back(n);
    ways.push_back(way);

    while (ways.size() > 0) {
      way = ways.back();
      ways.pop_back();

      int l = way.back();
      for (int i = 1; i < n + 1; i++) {
        bool flag0 = road[i] == l - i;
        bool flag1 = (road[i] == -(l - i) && -(l - i) == x);
        if (flag0 || flag1) {
          if (i == 1) {
            moves.push_back(way.size() + 1);
          } else {
            bool flag2 = true;
            bool flag3 = true;
            for (int j = 0; j < way.size(); j++) {
              if (way[j] == i) {
                flag2 = false;
              }
              if (j < way.size() - 1 && way[j] - way[j + 1] < 0) {
                flag3 = false;
              }
            }

            if ((flag0 && flag2) || (flag1 && flag2 && flag3)) {
              vector<int> newWay;
              copy(way.begin(), way.end(), back_inserter(newWay));
              newWay.push_back(i);
              ways.push_back(newWay);
            }
          }
        }
      }
    }
  }

  if (moves.size() == 0) {
    cout << -1;
  } else {
    int min = moves[0];
    for (int i = 1; i < moves.size(); i++) {
      if (min > moves[i]) {
        min = moves[i];
      }
    }
    cout << min;
  }
}
0