Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
92062193 Contestant:
SarthakBansal
1405C - 18 C++14 (GCC 6-32) Accepted 46 ms 8952 KB 2020-09-06 18:54:43 2020-09-06 20:09:23
→ Source
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define f(i,a,b) for(ll i=a;i<b;++i)
#define rof(i,a,b) for(ll i=a;i>b;--i)
#define endl "\n"  //632)D TLE 2000ms for endl and AC 499ms for \n
ll mod=1e9+7;
//cout << fixed << setprecision(14);
//cf dont use unordered map. use simply map<... , ... > m;
// dont use pow(2,_) use (1<<n)
//They are Iterator minus v.begin() krna //lower_bound(v.begin(),v.end(),x)-v.begin()  //upper_bound(v.begin(),v.end(),x)-v.begin()
// lower bound tells greater than or equal to // upper bound tells strictly greater than
//int a[1001][1001] //aise global me hi// ll lcm(ll a, ll b){ return a / __gcd(a, b) * b; }
//memset can initialize to 0 or -1 ONLY //memset(str, 't', sizeof(str)); // string //memset(a, 0, sizeof(a));  //1D array    // memset(a,0,sizeof(a[0][0])*n*n); //2D array
// set.insert(),find() //for(auto it=set.begin();....) cout<<*it;   // sort(v.begin(),v.end(),compare)
//bool lexicographical_compare(all(s1),all(s2)) //1 if s1<s2
//Binary Search socho. n me k size ka kaam krna  ho aur n<10^6,k<10^9 me O(nlogk) works. 1 se 1e9 pe Binary search maro har me O(n) kaam!
 //s1+=s2 zada time. use s1.append(s2).

string v[300005];
string ans;
void solve()
{
    ll n,k;cin>>n>>k;
    string s;cin>>s;

f(i,0,k) v[i]="";

ll index=0;
	f(i,0,n)
	{
		v[index]+=s[i];
		index++;
		if(index==k) index=0;
	}

//string
 ans="";
bool ex=true;
//v k len ka h
// cout<<v.size();
f(i,0,k)
{
	//v[i] poori hi h khud
char no='?';
f(j,0,v[i].length())
{
	if(v[i][j]=='1')
	{
		if(no=='0')
		{
			ex=false;
		}
		no='1';
	}
	if(v[i][j]=='0')
	{
		if(no=='1')
		{
			ex=false;
		}
		no='0';
	}
}

ans+=no;
}
ll z=0,o=0;
f(i,0,ans.length())
{
	if(ans[i]=='0') z++;
	else if(ans[i]=='1') o++;
}


if(z>k/2 || o>k/2)
{
	ex=false;
}

if(ex) cout<<"YES"<<endl;
else cout<<"NO"<<endl;

// v.clear();
//cout<<v.size();
}

int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
    cin>>t;
    while(t--)
    {
     solve();
    }
cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details