結果

問題 No.197 手品
ユーザー k
提出日時 2020-07-08 19:28:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 786 bytes
コンパイル時間 2,284 ms
コンパイル使用メモリ 204,608 KB
最終ジャッジ日時 2025-01-11 17:00:13
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

map<pair<string, int>, int> dist;

void go(string s, int d = 0) {
  if (d > 10) return;

  auto pr = make_pair(s, d%2);
  if (!dist.count(pr))
    dist[pr] = d;
  else
    dist[pr] = min(dist[pr], d);
  
  swap(s[0], s[1]);
  go(s, d+1);

  swap(s[0], s[1]);
  swap(s[1], s[2]);
  go(s, d+1);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s, t;
  int n;
  cin >> s >> n >> t;

  go(s);

  auto pr = make_pair(t, n%2);
  if (dist.count(pr) && dist[pr] <= n)
    cout << "FAILURE" << endl;
  else
    cout << "SUCCESS" << endl;

  return 0;
}
0