結果

問題 No.197 手品
ユーザー ty70ty70
提出日時 2015-05-29 00:03:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 3,068 bytes
コンパイル時間 888 ms
コンパイル使用メモリ 89,780 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 09:32:38
合計ジャッジ時間 2,771 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define SUCCESS 0
#define FAILURE 1

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const string pos[4][3] = {	{ "xxx", "xxx", "xxx" },
			 	{ "xxo", "xox", "oxx" },
				{ "xoo", "oxo", "oox" },
				{ "ooo", "ooo", "ooo" } }; 

const string res[2] = { "SUCCESS", "FAILURE" };

int main()
{
	ios_base::sync_with_stdio(0);

//	int T; cin >> T;
//	while (T-- ){

		string s_before; cin >> s_before;
		int N; cin >> N;
		string s_after; cin >> s_after;

		int nb = (int)count (ALL (s_before ), 'o' );
		int na = (int)count (ALL (s_after ),  'o' );

		int ans = -1;
		if (nb != na ){
			ans = SUCCESS;
		}else{
			int ind_before = -1;
			int ind_after  = -1;
			rep (i, 3 ) if (pos[nb][i] == s_before ) ind_before = i;
			rep (i, 3 ) if (pos[na][i] == s_after  ) ind_after = i;

			if (na == 0 || na == 3 ){
				ans = FAILURE;
			}else
			if (na == 1 ){
				// xxo -> xxo xox -> xox oxx -> oxx
				if (ind_before == ind_after ){
					if (ind_before == 0 || ind_before == 2 ){
						ans = FAILURE;
					}else{	// if (ind_before == 1 ) xox 
						if (N == 1 )
							ans = SUCCESS;
						else
							ans = FAILURE;
					} // end if
				}else{
					// xxo -> oxx  oxx -> xxo
					if (abs (ind_before - ind_after ) == 2 ){
						if (N <= 1 )
							ans = SUCCESS;
						else
							ans = FAILURE;
					// xxo -> xox xox -> oxx 
					}else{ // if (abs(ind_before - ind_after ) == 1 )
						if (N == 0 )
							ans = SUCCESS;
						else
							ans = FAILURE;
					} // end if
				} // end if
			}else{
				// xoo -> xoo oxo -> oxo oox -> oox	 
				if (ind_before == ind_after ){
					if (ind_before == 0 || ind_before == 2 ){
						ans = FAILURE;
					}else{	// if (ind_before == 1 ) oxo 
						if (N == 1 )
							ans = SUCCESS;
						else
							ans = FAILURE;
					} // end if
				}else{
					// xoo -> oox oox -> xoo
					if (abs (ind_before - ind_after ) == 2 ){
						if (N <= 1 )
							ans = SUCCESS;
						else
							ans = FAILURE;
					// xoo -> oxo oxo -> oox 
					}else{ // if (abs(ind_before - ind_after ) == 1 )
						if (N == 0 )
							ans = SUCCESS;
						else
							ans = FAILURE;
					} // end if
				} // end if
			} // end if
		} // end if
//		cerr << s_before << ' ' << N << ' ' << s_after << endl;
		cout << res[ans] << endl;
//	} // end while
	
	return 0;
}
0