結果

問題 No.1016 三目並べ
ユーザー pockynypockyny
提出日時 2020-04-03 22:40:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 1,142 ms
コンパイル使用メモリ 71,012 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-16 03:40:59
合計ジャッジ時間 1,553 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;
string s[5] = {"--o-","-o--","oo-","-oo","ooo"};
bool ch(string st,string u){
    int i,j,n = st.size(),k = u.size();
    for(i=0;i<n;i++){
        for(j=0;j<k;j++){
            if(i + j>=n || st[i + j]!=u[j]) break;
            if(j==k - 1) return true;
        }
    }
    return false;
}

bool ch2(string st){
    int i,n = st.size();
    int l = -1; bool flag = false;
    for(i=1;i<n;i++){
        if(st[i]=='-'){
            if(!flag) l = i - 1;
            flag = true;
        }else if(flag){
            flag = false;
            if(st[l]=='o' && st[i]=='o' && (i - l)%2==0){
                return true;
            }
        }
    }
    return false;
}
int main(){
    int i,t;
    cin >> t;
    while(t){
        t--;
        int n; string st;
        cin >> n >> st;
        for(i=0;i<5;i++){
            if(ch(st,s[i])){
                cout << "O" << endl;
                break;
            }
            if(i==4){
                if(ch2(st)) cout << "O" << endl;
                else cout << "X" << endl;
            }
        }
    }
}
0