singhsupriya711's blog

By singhsupriya711, history, 3 months ago, In English
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

try setting the datatype of integer to long long?

i don't see anything illegal here, just change from int to long long

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

This problem wants you to make the given string a 'k' copy of some random string. Suppose that random string contain a character say 'c' in it x times. So in the given string 's' it will be exactly k*x times. So first just calculate all occurrences of all characters, and check if it is perfectly divided by k or not, if it doesn't return -1 else print n copies of the string which will contain all characters 1/n times of its total.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Totally appreciate your effort! My code does that only ig,then why the test case 10 is failing I can't get that!

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      No you didn't do it that way. Lemme edit your code and send you. Maybe now you can understand your mistake. <3

      #include<bits/stdc++.h>
      using namespace std;
      
      #define int long long
      
      
      int32_t main(){
          ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
          int n;
          cin>>n;
          string s,ans;cin>>s;
          map<char,int> mp;
          for(int i=0;i<(int)s.length();i++){
              mp[s[i]]++;
          }
          bool t = true;
          for(auto it: mp){
          	if(it.second%n!=0){
          		t=false;
          		break;
          	}
          }
          if(!t)
          cout<<-1<<endl;
          else{
          	int m = n;
          	while(m--){
          		for(auto it: mp){
          			int z = it.second/n;
          			for(int i=0; i<z; i++)
          			cout<<it.first;
          		}
          	}
          	cout<<endl;
          }
      }