1678D - Tokitsukaze and Meeting - CodeForces Solution


dp implementation *1700

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(v) v.begin(), v.end()
#define done(x){ cout << x << endl;return;}
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i < n; i++)
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
void solve(){
    ll n,m;
    cin>>n>>m;
    string str;
    cin>>str;
    ll frr1[n*m+1],frr2[n*m+1];
    ll f[n*m+1];
    memset(frr1,0,sizeof frr1);
    memset(frr2,0,sizeof frr2);
    memset(f,0,sizeof f);
    ll cnt=0;
    f(i,n*m){
        if(str[i]=='1'){
            if(!f[i%m]){
                cnt++;
            }
            f[i%m]++;
        }
        frr1[i]=cnt;
    }
    cnt=0;
    f(i,n*m){
        if(i>=m){
            cnt-=(str[i-m]=='1');
        }
        cnt+=(str[i]=='1');
        frr2[i]=((i-m>=0)?frr2[i-m]:0)+((!cnt==0));
    }
    f(i,n*m){
        cout<<frr1[i]+frr2[i]<<" ";
    }
    cout<<endl;
    return ;
}
int main(){
    ll t;
    t = 1;
    scanf("%lld",&t);
    while (t--)
        solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1028B - Unnatural Conditions
735B - Urbanization
746C - Tram
1278B - A and B
1353D - Constructing the Array
1269C - Long Beautiful Integer
1076A - Minimizing the String
913C - Party Lemonade
1313A - Fast Food Restaurant
681A - A Good Contest
1585F - Non-equal Neighbours
747A - Display Size
285A - Slightly Decreasing Permutations
515C - Drazil and Factorial
1151E - Number of Components
1151F - Sonya and Informatics
556A - Case of the Zeros and Ones
867A - Between the Offices
1569A - Balanced Substring
260A - Adding Digits
1698C - 3SUM Closure
1029B - Creating the Contest
1421A - XORwice
1029A - Many Equal Substrings
1675D - Vertical Paths
1271C - Shawarma Tent
805A - Fake NP
1163A - Eating Soup
787A - The Monster
807A - Is it rated