提出 #60014422


ソースコード 拡げる

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
// typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>,
//             rb_tree_tag, tree_order_statistics_node_update>  ordered_set;
//member functions : order_of_key(k){no_of_ele < k} find_by_order(k){kth ele}

const ll M = 1e9 + 7;
const ll N = 1e5 + 69;
const ll lmax = 2e18;
const ll lmin = -2e18;

void solve()
{
    srand(time(0));
    int n, k; cin >> n >> k;
    string s; cin >> s;
    int ind = 0, start_k, end_k, curr_k_val = 0, end_k_neg;
    while (ind < s.size()) {
        while (ind < s.size() && s[ind] == '0') 
            ind++;
        curr_k_val++;
        if (curr_k_val == k) 
            start_k = ind;
        while (ind < s.size() && s[ind] == '1') 
            ind++;
        if (curr_k_val == k)
            end_k = ind - 1;
        if (curr_k_val == k - 1)
            end_k_neg = ind - 1;
    }
    // {0 to end_k_neg} + {end_k - start_k + 1} + {start_k - end_k_neg - 1} + {end_k + 1 to .}
    string ans = s.substr(0, end_k_neg + 1);
    for (int i = start_k; i <= end_k; i++)
        ans += '1';
    for (int i = end_k_neg + 1; i < start_k; i++)
        ans += '0';
    ans += s.substr(end_k + 1);
    cout << ans;
    return;
}

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    solve();
    return 0;
}

提出情報

提出日時
問題 C - Move Segment
ユーザ jeal0uspengu1n
言語 C++ 20 (gcc 12.2)
得点 300
コード長 1609 Byte
結果 AC
実行時間 3 ms
メモリ 4840 KiB

コンパイルエラー

Main.cpp: In function ‘void solve()’:
Main.cpp:24:16: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   24 |     while (ind < s.size()) {
      |            ~~~~^~~~~~~~~~
Main.cpp:25:20: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   25 |         while (ind < s.size() && s[ind] == '0')
      |                ~~~~^~~~~~~~~~
Main.cpp:30:20: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   30 |         while (ind < s.size() && s[ind] == '1')
      |                ~~~~^~~~~~~~~~
Main.cpp:38:40: warning: ‘end_k_neg’ may be used uninitialized [-Wmaybe-uninitialized]
   38 |     string ans = s.substr(0, end_k_neg + 1);
      |                              ~~~~~~~~~~^~~
Main.cpp:23:50: note: ‘end_k_neg’ was declared here
   23 |     int ind = 0, start_k, end_k, curr_k_val = 0, end_k_neg;
      |                                                  ^~~~~~~~~
Main.cpp:43:27: warning: ‘end_k’ may be used uninitialized [-Wmaybe-uninitialized]
   43 |     ans += s.substr(end_k + 1);
      |                     ~~~~~~^~~
Main.cpp:23:27: note: ‘end_k’ was declared here
   23 |     int ind = 0, start_k, end_k, curr_k_val = 0, end_k_neg;
      |                           ^~~~~
Main.cpp:41:35: warning: ‘start_k’ may be used uninitialized [-Wmaybe-uninitialized]
   41 |     for (int i = end_k_neg + 1; i < start_k; i++)
      |                                 ~~^~~~~~~~~
Main.cpp:23:18: note: ‘start_k’ was declared here
   23 |     int ind = 0, start_k, end_k, curr_k_val = 0, end_k_neg;
      |                  ^~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 28
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
min.txt AC 1 ms 3580 KiB
random_01.txt AC 3 ms 4756 KiB
random_02.txt AC 3 ms 4576 KiB
random_03.txt AC 3 ms 4756 KiB
random_04.txt AC 3 ms 4792 KiB
random_05.txt AC 3 ms 4780 KiB
random_06.txt AC 3 ms 4824 KiB
random_07.txt AC 1 ms 3740 KiB
random_08.txt AC 2 ms 4504 KiB
random_09.txt AC 1 ms 3792 KiB
random_10.txt AC 3 ms 4840 KiB
random_11.txt AC 2 ms 4524 KiB
random_12.txt AC 2 ms 4764 KiB
random_13.txt AC 1 ms 3756 KiB
random_14.txt AC 3 ms 4612 KiB
random_15.txt AC 1 ms 3632 KiB
random_16.txt AC 2 ms 4572 KiB
random_17.txt AC 2 ms 4776 KiB
random_18.txt AC 3 ms 4420 KiB
random_19.txt AC 2 ms 4476 KiB
random_20.txt AC 2 ms 4612 KiB
random_21.txt AC 1 ms 3916 KiB
random_22.txt AC 3 ms 4836 KiB
random_23.txt AC 1 ms 3712 KiB
random_24.txt AC 2 ms 4500 KiB
random_25.txt AC 2 ms 4324 KiB
sample_01.txt AC 1 ms 3628 KiB
sample_02.txt AC 1 ms 3700 KiB