結果

問題 No.2283 Prohibit Three Consecutive
ユーザー 👑 kakel-sankakel-san
提出日時 2023-07-24 00:08:37
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,697 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 111,516 KB
実行使用メモリ 29,288 KB
最終ジャッジ日時 2023-10-25 07:50:35
合計ジャッジ時間 2,915 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
25,208 KB
testcase_01 AC 29 ms
25,208 KB
testcase_02 AC 29 ms
25,208 KB
testcase_03 AC 41 ms
26,028 KB
testcase_04 AC 41 ms
26,068 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 34 ms
25,188 KB
testcase_09 AC 35 ms
25,188 KB
testcase_10 AC 34 ms
25,192 KB
testcase_11 AC 35 ms
25,192 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = NN;
        var ans = new bool[t];
        for (var u = 0; u < t; ++u)
        {
            var n = NN;
            var s = ReadLine();
            ans[u] = Three(n, s);
        }
        WriteLine(string.Join("\n", ans.Select(f => f ? "Yes" : "No")));
    }
    static bool Three(int n, string s)
    {
        var c = s.ToList();
        c.Add(s[0]);
        c.Add(s[1]);
        for (var i = 0; i + 2 < c.Count; ++i)
        {
            if (c[i] == '0' && c[i + 1] == '0' && c[i + 2] == '?') c[i + 2] = '1';
            if (c[i] == '1' && c[i + 1] == '1' && c[i + 2] == '?') c[i + 2] = '0';
        }
        for (var i = c.Count - 3; i >= 0; --i)
        {
            if (c[i] == '?' && c[i + 1] == '0' && c[i + 2] == '0') c[i] = '1';
            if (c[i] == '?' && c[i + 1] == '1' && c[i + 2] == '1') c[i] = '0';
        }
        var len = 0;
        var last = 'a';
        for (var i = 0; i < c.Count; ++i)
        {
            if (c[i] != last || c[i] == '?')
            {
                len = 1;
                last = c[i];
            }
            else ++len;
            if (len == 3)
            {
                return false;
            }
        }
        return true;
    }
}
0