結果

問題 No.1016 三目並べ
ユーザー tonyu0
提出日時 2020-04-03 23:47:09
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 11,713 ms
コンパイル使用メモリ 401,372 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 06:34:26
合計ジャッジ時間 12,527 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let t: usize = itr.next().unwrap().parse().unwrap();
    let mut out = Vec::new();
    for _ in 0..t {
        let n: usize = itr.next().unwrap().parse().unwrap();
        let s: Vec<char> = itr.next().unwrap().chars().collect();
        let mut o = false;
        let mut idx = 0;
        while idx < n {
            if s[idx] == 'o' {
                let mut oo = 0;
                idx += 1;
                while idx < n && s[idx] == '-' {
                    oo += 1;
                    idx += 1;
                }
                if idx < n && s[idx] == 'o' && oo % 2 != 0 {
                    o = true;
                }
            } else {
                idx += 1;
            }
        }

        if n > 2 {
            for i in 0..n - 2 {
                if s[i] == 'o' && s[i + 1] == 'o' && s[i + 2] != 'x' {
                    o = true;
                }
                if s[i] != 'x' && s[i + 1] == 'o' && s[i + 2] == 'o' {
                    o = true;
                }
                if i < n - 3 {
                    if s[i] == '-' && s[i + 1] == 'o' && s[i + 2] == '-' && s[i + 3] == '-' {
                        o = true;
                    }
                    if s[i] == '-' && s[i + 1] == '-' && s[i + 2] == 'o' && s[i + 3] == '-' {
                        o = true;
                    }
                }
            }
        }

        if o {
            writeln!(out, "O").ok();
        } else {
            writeln!(out, "X").ok();
        }
    }
    stdout().write_all(&out).unwrap();
}
0