Submission #59841277


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n, k, m = 0, t[N];
char s[N];
pair<int, int> B[N];
int main() {
ios :: sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> k;
cin >> (s + 1);
for (int i = 1; i <= n; i++) {
if (s[i] == '1') {
if (i == 1 || s[i - 1] == '0') {
++m;
B[m] = {i, i};
} else {
B[m].second = i;
}
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n, k, m = 0, t[N];
char s[N];
pair<int, int> B[N];
int main() {
    ios :: sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> k;
    cin >> (s + 1);
    for (int i = 1; i <= n; i++) {
        if (s[i] == '1') {
            if (i == 1 || s[i - 1] == '0') {
                ++m;
                B[m] = {i, i};
            } else {
                B[m].second = i;
            }
        }
    }
    for (int i = 1; i <= m; i++) {
        int l = B[i].first;
        int r = B[i].second;
        if (i == k) {
            r = B[i - 1].second + r - l + 1;
            l = B[i - 1].second + 1;
        }
        for (int j = l; j <= r; j++) t[j] = 1;
    }
    for (int i = 1; i <= n; i++) cout << t[i];
    return 0;
}

Submission Info

Submission Time
Task C - Move Segment
User Tianyiwei
Language C++ 17 (gcc 12.2)
Score 300
Code Size 838 Byte
Status AC
Exec Time 15 ms
Memory 7868 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 28
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 3464 KB
random_01.txt AC 15 ms 7868 KB
random_02.txt AC 15 ms 7824 KB
random_03.txt AC 14 ms 6056 KB
random_04.txt AC 13 ms 3964 KB
random_05.txt AC 14 ms 4928 KB
random_06.txt AC 15 ms 6016 KB
random_07.txt AC 2 ms 3612 KB
random_08.txt AC 14 ms 5544 KB
random_09.txt AC 4 ms 4000 KB
random_10.txt AC 15 ms 6100 KB
random_11.txt AC 13 ms 5692 KB
random_12.txt AC 14 ms 5552 KB
random_13.txt AC 2 ms 3576 KB
random_14.txt AC 15 ms 5960 KB
random_15.txt AC 2 ms 3664 KB
random_16.txt AC 14 ms 5560 KB
random_17.txt AC 14 ms 4952 KB
random_18.txt AC 15 ms 6036 KB
random_19.txt AC 12 ms 5576 KB
random_20.txt AC 14 ms 5728 KB
random_21.txt AC 5 ms 3992 KB
random_22.txt AC 15 ms 6080 KB
random_23.txt AC 4 ms 4240 KB
random_24.txt AC 14 ms 5624 KB
random_25.txt AC 11 ms 4712 KB
sample_01.txt AC 1 ms 3384 KB
sample_02.txt AC 1 ms 3396 KB


2025-03-05 (Wed)
18:09:58 +00:00