SQULET - Editorial

Contest

Author: Mrudula Umalkar
Tester: Toshit Kale
Editorialist: Mrudula Umalkar

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Strings

PROBLEM:

Given 2 strings of length N represents two groups and determines which group moves to the next level.

QUICK EXPLANATION:

Traverse the string in any one direction. Determine whether the group follows both the given condition or not and output according to it.

EXPLANATION:

As per the given problem, the necessary condition for a group to move to the next level is,
(1) There must be an equal number of male (m) and female (f) players.
(2) Male and female players must have an alternate position.
To satisfy condition (1) N always have to be Even because that’s one of the way that there are
equal no of male and female players and to check
condition (2) we traverse through a string in any one direction and check s[i]!=s[i+1] where s is a string and i is the index of characters.

Output “first” if group 1 wins, “second” if group 2 wins, “tie” if both groups satisfy the condition,
and “-1” if both groups don’t.

Time Complexity: O(n) per test case, where n is the length of a string.

SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
#define ul unsigned long long int
#define ll long long int
#define pb push_back
#define mod 1000000007
using namespace std;
ll team(string s,ll a)
{
ll flag=1;
for(ll i=0;i<a-1;i++){
   if(s[i]==s[i+1])
   flag=0;
 }
if(flag){
    return 1;
}
else{
    return 0;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--){
 ll n;
 cin>>n;
string s1,s2;
cin>>s1>>s2;
if(n%2!=0){
    cout<<-1<<"\n";
}
else{
  ll x1= team(s1,n);
  ll x2= team(s2,n);
if(x1&x2){
   cout<<"tie"<<"\n";
}
else if(x1){
   cout<<"first"<<"\n";
}
else if(x2){
   cout<<"second"<<"\n";
}
else{
   cout<<-1<<"\n";
   }
 }
 }
return 0;
}
Tester's Solution
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define  rep(i,b) for (ll i =1; i <= (b); i++)
#define mod 1000000007 
#define  rep(i,b) for (ll i =1; i <= (b); i++)
#define  repp(i,b) for (ll i =0; i < (b); i++)
#define test int t; cin>>t; while(t--)
#define fio ios_base::sync_with_stdio(false);  cin.tie(NULL)
#define test int t; cin>>t; while(t--)
#define pb push_back
#define F first
#define S second
#define s(n) scanf("%lld",&n)
typedef vector<ll> vi;
int main(){
  #ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio;
test{
  ll n;
  cin>>n;
  string s,ss;
  cin>>s>>ss;
  if(n&1){
        cout<<-1<<endl;
  }
  else{
        ll f=1,se=1;
        repp(i,n-1){
              if(s[i]==s[i+1])f=0;
              if(ss[i]==ss[i+1])se=0;
        }
        // cout<<f<<" "<<se<<endl;
        if(f&se)cout<<"tie"<<endl;
        else if(f)cout<<"first"<<endl;
        else if(se)cout<<"second"<<endl;
        else cout<<-1<<endl;
  }
}
}