我是傻逼!!!!!!!!!

· · 个人记录

22.10.9 ARC

整场只做出来第一道题。

警钟敲烂。

#include <bits/stdc++.h>
using namespace std;
const int N = 3e5, MAX_N = N + 3;
char s [MAX_N];
set <int> pos;
signed main () {
    int cas, n, K;
    scanf ("%d", &cas);
    while (cas--) {
        pos.clear ();
        scanf ("%d%d%s", &n, &K, s + 1);
        int L = 0, R;
        for (int i = 1; i <= n; ++i) {
            if (s [i] == '1') {
                if (!L) L = i;
                R = i;
            }
            if (s [i] == '0') pos.insert (i);
        }
        int cnt = 0;
        for (int l = 1, r = K; r <= n; ++l, ++r)
            cnt += (!L || l <= L && R <= r) && (pos.lower_bound (l) == pos.end () || *(pos.lower_bound (l)) > r);
        puts (cnt == 1 ? "Yes" : "No");
    }
}

反思: