結果

問題 No.197 手品
ユーザー odan3240odan3240
提出日時 2016-01-06 23:35:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,748 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 105,528 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 20:42:30
合計ジャッジ時間 2,467 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

string S1,S2;
ll N;
int cnt(string s) {
    int ret=0;
    rep(i,s.size()) if(s[i]=='o') ret++;
    return ret;
}

int bfs() {
    queue<pair<string,int>> que;
    que.push(mp(S1,0));
    map<string, int> d;
    d[S1]=0;
    while(que.size()) {
        auto state=que.front(); que.pop();
        
        string tmp=state.first;
        swap(tmp[0],tmp[1]);
        if(d.count(tmp)==0) {
            d[tmp]=d[state.first]+1;
            que.push(mp(tmp,d[tmp]));
        }
        tmp=state.first;
        swap(tmp[1],tmp[2]);
        if(d.count(tmp)==0) {
            d[tmp]=d[state.first]+1;
            que.push(mp(tmp,d[tmp]));
        }
    }

    return d[S2];
}

int main() {
    cin>>S1>>N>>S2;
    if(cnt(S1)!=cnt(S2)) {
        cout<<"SUCCESS"<<endl;
        return 0;
    }
    if(N==0) {
        if(S1==S2) cout<<"FAILURE"<<endl;
        else cout<<"SUCCESS"<<endl;
        return 0;
    }
    if(N>=2) {
        cout<<"FAILURE"<<endl;
        return 0;
    }

    int d=bfs();
    if(d==1) {
        cout<<"FAILURE"<<endl;
    }
    else {
        cout<<"SUCCESS"<<endl;
    }
    return 0;
}
0