結果
問題 |
No.197 手品
|
ユーザー |
![]() |
提出日時 | 2015-04-28 23:27:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 644 bytes |
コンパイル時間 | 1,852 ms |
コンパイル使用メモリ | 173,020 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 07:08:10 |
合計ジャッジ時間 | 2,855 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 WA * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long f(string s,string t){ queue<string> Q; map<string,int> ok; Q.push(s); ok[s] = 0; while( Q.size() ){ string q = Q.front(); Q.pop(); if( q == t ){ return ok[q]; } for(int i = 0 ; i < 3 ; i++) for(int j = i+1 ; j < 3 ; j++){ if( j-i > 1 ) continue; string w = q; swap(w[i],w[j]); if( !ok.count(w) ){ ok[w] = ok[q] + 1; Q.push(w); } } } return 1e15; } int main(){ string s,t; int N; cin >> s >> N >> t; long long r = f(s,t); if( r > N ) { cout << "SUCCESS" << endl; }else{ cout << ((N-r)%2?"SUCCESS":"FAILURE") << endl; } }