Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

manalibiswas's blog

By manalibiswas, history, 9 months ago, In English,

include<bits/stdc++.h>

using namespace std;

void find(char m,int&p,int&q) { if(m=='W') ++p; else ++q; } int main() { int n,k,i,p,q; char x; vector a; cin>>n>>k;

for(int i=0;i<n;i++)
{
    cin>>x;
    a.push_back(x);
}
a.push_back('\0');

for(int l=0,i=0;l<k&&i<n;l++)
{
    vector<char>b;
    for(int j=0;j<n;j++)
    {p=q=0;
        if(j==0)
        {
            find(a[n-1],p,q);
            find(a[0],p,q);
            find(a[1],p,q);
        }
        else if(j==(n-1))
        {
            find(a[0],p,q);
            find(a[n-1],p,q);
            find(a[n-2],p,q);
        }
        else
        {
            find(a[j-1],p,q);
            find(a[j+1],p,q);
            find(a[j],p,q);
        }
        b.push_back(p>q?'W':'B');
        if(a[j]==b[j]) i++;
    }
    b.push_back('\0');
    a=b;
}
for(int j=0;j<n;j++)
    cout<<a[j];
cout<<'\0';
return 0;

}

This is my submission for the problem.. Even the wrong test case on first test case shows right answer but still showing wrong answer? And showing right answer for the example cases on other interfaces but not here

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
9 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Hi fixed your code for you.

Just removed cout<<'\0'; at the end of your code.

Also, your algorithm is too slow as it is worst case O(N^2).