1165A - Remainder - CodeForces Solution


implementation math *1100

Please click on ads to support us..

Python Code:

n,x,y = list(map(int,input().split()))
s = input()
ans = 0
for i in range(n-x,n):
    if i==n-y-1:
        ans+= s[i] != '1'
    else:
        ans+= s[i] != '0'
print(ans)

C++ Code:

    #include <bits/stdc++.h>
    /*--------------------------------------------------------------------------------------------------------*/
    #define ImFastAsFuckBoi cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); cout.sync_with_stdio(0);
    #define endl "\n"
    #define Sort(x) sort(x.begin(),x.end())
    #define Sortr(x) sort(x.rbegin(),x.rend())
    #define Reverse(x) reverse(x.begin(),x.end())
    #define input(x) for(auto &it:x) cin >> it
    #define print(x,ssss) for(auto it : x) cout << it << ssss
    #define int long long
    #define Cnt(s,ch) c(s.begin(), s.end(), ch)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    /*--------------------------------------------------------------------------------------------------------*/
    using namespace std;
    /*--------------------------------------------------------------------------------------------------------*/
    void YES(bool t = 1) { t ? cout << "YES" : cout << "NO"; }
    void NO(bool t = 1) { YES(!t); }
    void Yes(bool t = 1) { t ? cout <<  "Yes" : cout << "No"; }
    void No(bool t = 1) { Yes(!t); }
    void yes(bool t = 1) { t ? cout << "yes" : cout << "no"; }
    void no(bool t = 1) { yes(!t); }
    /*--------------------------------------------------------------------------------------------------------*/
    //  "My pops said I needed a job."
    //  - Kendrick Lamar
    /*--------------------------------------------------------------------------------------------------------*/


    int n,num,c,x,y,cnt;
    string s;
    void solve()
    {
        cin >> n  >> x >> y>> s;
        for(int i =n-1; i >= n-x; i--){
            if(i == (n-y-1)){
                if(s[i]=='0') cnt++;
            }
            else if(s[i]=='1') cnt++;
        }
        cout << cnt;
    }

    main ()
    {
        ImFastAsFuckBoi    //freopen("equal.in","r",stdin);
        int test_case=1;  //cin >> test_case;

        while(test_case--)
        {
            solve();
            cout << endl;
        }
    }


Comments

Submit
0 Comments
More Questions

869. Reordered Power of 2
1593C - Save More Mice
1217. Minimum Cost to Move Chips to The Same Position
347. Top K Frequent Elements
1503. Last Moment Before All Ants Fall Out of a Plank
430. Flatten a Multilevel Doubly Linked List
1290. Convert Binary Number in a Linked List to Integer
1525. Number of Good Ways to Split a String
72. Edit Distance
563. Binary Tree Tilt
1306. Jump Game III
236. Lowest Common Ancestor of a Binary Tree
790. Domino and Tromino Tiling
878. Nth Magical Number
2099. Find Subsequence of Length K With the Largest Sum
1608A - Find Array
416. Partition Equal Subset Sum
1446. Consecutive Characters
1618A - Polycarp and Sums of Subsequences
1618B - Missing Bigram
938. Range Sum of BST
147. Insertion Sort List
310. Minimum Height Trees
2110. Number of Smooth Descent Periods of a Stock
2109. Adding Spaces to a String
2108. Find First Palindromic String in the Array
394. Decode String
902. Numbers At Most N Given Digit Set
221. Maximal Square
1200. Minimum Absolute Difference