Submission #69860587


Source Code Expand

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        string s;
        cin >> n >> s;

        int ans = INT_MAX;
        vector<int> cnt(2, 0);
        for(int i = 0; i < n; i++){
            if(s[i] == '0') cnt[0]++;
            else cnt[1]++;
        }

        for(int i = 0; i < n; i++){
            // cout << i << endl;
            int j;
            for(j = i; j < n; j++){
                if(s[i] != s[j]) break;
            }

            int v;
            if(s[i] == '0') v = min(cnt[0] - (j-i), cnt[1]);
            else v = min(cnt[0], cnt[1] - (j-i));
            ans = min(ans, i + n-j + v);

            i = j-1;
        }
        cout << ans << endl;
    }
}

Submission Info

Submission Time
Task D - Pop and Insert
User sakimori_coder
Language C++ 20 (gcc 12.2)
Score 0
Code Size 802 Byte
Status WA
Exec Time 57 ms
Memory 4332 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 1
AC × 13
WA × 1
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_small_00.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3480 KiB
01_small_00.txt WA 57 ms 3536 KiB
02_random_00.txt AC 9 ms 3556 KiB
02_random_01.txt AC 7 ms 3504 KiB
02_random_02.txt AC 7 ms 3660 KiB
02_random_03.txt AC 7 ms 4332 KiB
02_random_04.txt AC 7 ms 4164 KiB
02_random_05.txt AC 9 ms 4144 KiB
02_random_06.txt AC 8 ms 4124 KiB
03_handmade_00.txt AC 7 ms 4176 KiB
03_handmade_01.txt AC 7 ms 4152 KiB
03_handmade_02.txt AC 8 ms 4160 KiB
03_handmade_03.txt AC 7 ms 4188 KiB
03_handmade_04.txt AC 7 ms 4152 KiB