結果

問題 No.2283 Prohibit Three Consecutive
ユーザー 👑 kakel-sankakel-san
提出日時 2023-07-24 02:59:41
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 3,675 ms
コンパイル使用メモリ 111,560 KB
実行使用メモリ 29,292 KB
最終ジャッジ日時 2023-10-25 10:41:57
合計ジャッジ時間 4,055 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
25,208 KB
testcase_01 AC 28 ms
25,204 KB
testcase_02 AC 28 ms
25,204 KB
testcase_03 AC 43 ms
26,012 KB
testcase_04 AC 43 ms
26,060 KB
testcase_05 AC 53 ms
27,244 KB
testcase_06 AC 53 ms
27,244 KB
testcase_07 AC 28 ms
25,204 KB
testcase_08 AC 35 ms
25,196 KB
testcase_09 AC 35 ms
25,196 KB
testcase_10 AC 35 ms
25,196 KB
testcase_11 AC 36 ms
25,196 KB
testcase_12 AC 42 ms
27,244 KB
testcase_13 AC 58 ms
29,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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();
        for (var i = 0; i < c.Count; ++i)
        {
            if (c[i] == '0' && c[(i + 1) % n] == '0' && c[(i + 2) % n] == '?') c[(i + 2) % n] = '1';
            if (c[i] == '1' && c[(i + 1) % n] == '1' && c[(i + 2) % n] == '?') c[(i + 2) % n] = '0';
        }
        for (var i = c.Count - 1; i >= 0; --i)
        {
            if (c[i] == '?' && c[(i + 1) % n] == '0' && c[(i + 2) % n] == '0') c[i] = '1';
            if (c[i] == '?' && c[(i + 1) % n] == '1' && c[(i + 2) % n] == '1') c[i] = '0';
        }
        for (var i = 0; i < c.Count; ++i)
        {
            if (c[i] != '?' && c[i] == c[(i + 1) % n] && c[i] == c[(i + 2) % n])
            {
                return false;
            }
        }
        return true;
    }
}
0