結果

問題 No.2283 Prohibit Three Consecutive
ユーザー JlyfishJlyfish
提出日時 2023-05-05 13:46:12
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,928 bytes
コンパイル時間 6,070 ms
コンパイル使用メモリ 244,056 KB
最終ジャッジ日時 2025-02-12 17:10:01
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'void Solution()':
main.cpp:12:14: error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} and 'char*')
   12 |     cin >> n >> (s + 1);
      |     ~~~~~~~~ ^~ ~~~~~~~
      |         |          |
      |         |          char*
      |         std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/sstream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/complex:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/ccomplex:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/istream:168:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  168 |       operator>>(bool& __n)
      |       ^~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/istream:168:7: note:   conversion of argument 1 would be ill-formed:
main.cpp:12:20: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'char*'
   12 |     cin >> n >> (s + 1);
      |                 ~~~^~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/istream:172:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  172 |       operator>>(short& __n);
      |       ^~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/istream:172:7: note:   conversion of argument 1 would be ill-formed:
main.c

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int N = 100010;

int n;
bool dp[N][2][2];
char s[N];

void Solution() {
    cin >> n >> (s + 1);
    if (n <= 2) {
        cout << "Yes\n";
        return;
    }

    bool ans = false;
    for (int l = 0; l < 2; l++) {
        if (s[1] != '?' && s[1] - '0' != l) continue;
        for (int r = 0; r < 2; r++) {
            if (s[2] != '?' && s[2] - '0' != r) continue;
            for (int i = 2; i <= n; i++) {
                for (int j = 0; j < 2; j++) {
                    for (int k = 0; k < 2; k++) {
                        dp[i][j][k] = false;
                    }
                }
            }
            dp[2][l][r] = true;
            for (int i = 3; i <= n; i++) {
                for (int p = 0; p < 2; p++) {
                    // dp[i - 1][p][j] -> dp[i][j][k]
                    for (int j = 0; j < 2; j++) {
                        auto upd = [&](int k) {
                            if (j == p && j == k) return;
                            dp[i][j][k] |= dp[i - 1][p][j];
                        };
                        if (s[i] == '?') {
                            for (int k = 0; k < 2; k++) upd(k);
                        } else {
                            upd(s[i] - '0');
                        }
                    }
                }
            }

            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    if (!dp[n][i][j]) continue;
                    ans |= (!(i == j && j == l) && !(j == l && l == r));
                }
            }
        }
    }
    cout << (ans ? "Yes" : "No") << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            dp[0][i][j] = true;
        }
    }
    
    int testCase;
    cin >> testCase;
    while (testCase--) Solution();
    return 0;
}
0