Submission #1291977

#TimeUsernameProblemLanguageResultExecution timeMemory
1291977M_SH_OFlip it and Stick it (CCO23_day2problem1)C++20
4 / 25
4 ms720 KiB
/*#pragma GCC optimize("O3")
#pragma GCC optimization("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")*/
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/

#define ll long long
#define ll1 long long
#define ull unsigned long long
#define dou long double
#define str string
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define vbool vector<bool>
#define vstr vector<str>
#define vvll vector<vll>
#define pb push_back
#define pf push_front
#define endl "\n"
#define fr first
#define se second
// #define sortcmp(a) sort(a.begin(), a.end(), cmp)
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
//using namespace __gnu_pbds;

const ll INF = 1e18+7;
const int lg = 20;
//const ll MOD = 1e9+7;
//const ll MOD2 = 998244353;
const ll MOD3 = 1e6+3;

mt19937 rng(1488);
ll randll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

int main() {
    speed;

    str s, s1;
    cin >> s;
    cin >> s1;
    if (s1.size() == 1) {
        sort(s);
        if (str(1, s[0]) == s1 || str(1, s[s.size()-1]) == s1) cout << -1 << endl;
        else cout << 0 << endl;
    }
    else if (s1.size() == 2 && s1[0] != s1[1]){
        if (s1[0] == '0') reverse(s);
        ll k = 0;
        for (int i = 0; i < s.size(); i ++) {
            if (s[i] == '0') continue;
            if (i == 0 || s[i-1] == '0') k ++;
        }
        if (s[s.size()-1] == '1') k --;
        cout << k << endl;
    }
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...