QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#166852#6860. Binary NumberPPP#AC ✓73ms4500kbC++171.3kb2023-09-06 19:30:252023-09-06 19:30:26

Judging History

你现在查看的是最新测评结果

  • [2023-09-06 19:30:26]
  • 评测
  • 测评结果:AC
  • 用时:73ms
  • 内存:4500kb
  • [2023-09-06 19:30:25]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
ll k;
const int maxN = 1e5 + 10;
int A[maxN];
int B[maxN];
void solve() {
    cin >> n >> k;
    string s;
    cin >> s;
    A[1] = (s[0] - '0');
    for (int i = 2; i <= n; i++) {
        A[i] = ((s[i - 1] - '0') ^ (s[i - 2] - '0'));
    }
    A[n + 1] = (s[n - 1] - '0');
    A[0] = 0;
    B[0] = 0;
    int lst = 0;
    int dif = 0;
    if (n == 1) {
        if (k % 2 == 0) cout << 1;
        else cout << 0;
        cout << '\n';
        return;
    }
    for (int i = 1; i <= n; i++) {
        for (int j : {lst ^ 1, lst}) {
            B[i] = j;
            int ndif = dif + (A[i] != B[i]);
            if (i == n) {
                if (ndif % 2 != 0) ndif++;
            }
            if (ndif > 2 * k) continue;
            if (ndif < 2 * k && i == n && k == 1) continue;
            lst ^= B[i];
            dif = ndif;
            break;
        }
        cout << lst;
    }
    cout << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst;
    cin >> tst;
    while (tst--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 73ms
memory: 4500kb

input:

59471
11 523478562876
11011111010
10 1000
1110101110
11 13333
10101000011
11 9
10000001001
11 1000
10110100100
11 4
11000010111
11 1000
11100100011
11 100
10000000001
11 23333
10111101110
9 233
110110010
11 648953764538
10011110011
9 233333
101010111
11 9
10001011001
11 8
10100001100
10 77777777
100...

output:

11111111111
1111111111
11111111111
11111111111
11111111111
11111111111
11111111111
11111111111
11111111111
111111111
11111111111
111111111
11111111111
11111111111
1111111111
11111111111
11111111111
11111111010
11111111111
11111111111
11111111111
11111111111
11111111000
11111111111
1111010
1111111111...

result:

ok 59471 lines