# EQUINOX - Editorial

Setter: Anshul Garg
Tester & Editorialist: Taranpreet Singh

Cakewalk

None

# PROBLEM

Given N words consisting of Uppercase English characters and two integers A and B, two players Sarthak and Anuradha play a game. For each word, if the first character of the word appears in string “EQUINOX”, Sarthak gets A points, otherwise Anuradha gets B points. The person with higher score wins.

# QUICK EXPLANATION

• Simulate the process, maintaining the scores and compare them.

# EXPLANATION

Since this is an easier problem, all we need to do is to simulate the game. Start with scores for both players being zero and consider word one by one.

To check if first characters appears in string EQUINOX, one naive way would be to write 7 if conditions. It works, but too much work for nothing. We can simplify it.

One way would be to us would be to create a string EQUINOX and use the inbuild find function to check whether the character appears in string EQUINOX or not.

Another way would be to make an array or a set.

Following code snippet depict the intended solution

string EQUINOX = "EQUINOX"
SarthakScore = 0
for word in wordList:
if word[0] in EQUINOX:
SarthakScore += A
else:


Don’t forget to use long data type, since the scores can easily go beyond 32 bit integer range.

# TIME COMPLEXITY

The time complexity is O(\sum |S_i|) per test case, since we read that as input.

# SOLUTIONS

Setter's Solution
#include <bits/stdc++.h>
using namespace std;

const int mod = 1000000007;
#define int long long

string tt = "EQUINOX";

void solve(){
int n, a, b;
int ans1 = 0, ans2 = 0; cin >> n >> a >> b;
for(int i = 0; i < n; i++){
string s; cin >> s;
int f = 0;
for(int j = 0; j < tt.size(); j++){
if(tt[j] == s[0]) f = 1;
}
if(f) ans1 += a;
else ans2 += b;
}
if(ans1 == ans2) cout << "Draw\n";
else if(ans1 > ans2) cout << "Sarthak\n";
}

signed main(){
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t;
cin >> t;
while(t--) solve();
}

Tester's Solution
import java.util.*;
import java.io.*;
class EQUINOX{
//SOLUTION BEGIN
void pre() throws Exception{}
void solve(int TC) throws Exception{
int N = ni();
long A = nl(), B = nl();
long sarthak = 0, anuradha = 0;
String pattern = "EQUINOX";
for(int i = 0; i< N; i++){
String word = n();
if(pattern.contains(word.substring(0,1)))sarthak += A;
}
else pn("draW");
}
//SOLUTION END
void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
static boolean multipleTC = true;
void run() throws Exception{
out = new PrintWriter(System.out);
//Solution Credits: Taranpreet Singh
int T = (multipleTC)?ni():1;
pre();for(int t = 1; t<= T; t++)solve(t);
out.flush();
out.close();
}
public static void main(String[] args) throws Exception{
new EQUINOX().run();
}
int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
void p(Object o){out.print(o);}
void pn(Object o){out.println(o);}
void pni(Object o){out.println(o);out.flush();}
String n()throws Exception{return in.next();}
String nln()throws Exception{return in.nextLine();}
int ni()throws Exception{return Integer.parseInt(in.next());}
long nl()throws Exception{return Long.parseLong(in.next());}
double nd()throws Exception{return Double.parseDouble(in.next());}

StringTokenizer st;
}

}

String next() throws Exception{
while (st == null || !st.hasMoreElements()){
try{
}catch (IOException  e){
throw new Exception(e.toString());
}
}
return st.nextToken();
}

String nextLine() throws Exception{
String str = "";
try{
}catch (IOException e){
throw new Exception(e.toString());
}
return str;
}
}
}


Feel free to share your approach. Suggestions are welcomed as always.

can you please share editorial in java…it was giving me TLE.

Solution: 45687865 | CodeChef

why my sol not working i feel my logic right

1 Like

Try this input:

1
2 1 100
X
P


1 Like

why my code is not working just throwing WA.
https://www.codechef.com/viewsolution/45690806

I write perfect code. but it shows wrong ans. Can anyone tell me whats wrong in my code?

#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
int main()
{
long long int t;
cin >> t;
long long int n, a, b;
while(t–)
{
cin >> n >> a >> b;
int sc1 = 0;
int sc2 = 0;
string s;
toupper(s[0]);
for(int i = 0; i < n; i++)
{
cin >> s;
if(s[0] == ‘E’ || s[0] == ‘Q’ || s[0] == ‘U’ || s[0] == ‘I’ || s[0] == ‘N’ || s[0] == ‘O’ || s[0] == ‘X’)
{
sc1 += a;
} else {
sc2 += b;
}
}
if(sc1 > sc2)
{
cout << “SARTHAK” << endl;
}
else if (sc1 < sc2)
{
}
else {
cout << “DRAW” << endl;
}
}
return 0;
}

2 Likes

My code is in java only.

https://www.codechef.com/viewsolution/45688903
Where is the mistake . pls anyone can tell?

Hello

@cubefreak777 and other coders please try to debug the error. Because of this problem I lost 70 points

Solution

On again going back to successful solutions. I am shocked to see a correct answer with same logic

Solution

#include
using namespace std;

int main() {
int t,n,a,b;
char ch;
cin>>t;

for(int i=0;i<t;i++)
{
cin>>n>>a>>b;

 for(int i=0;i<=n;i++)
{
string S;
getline(cin, S);

if(S[0]=='E' || S[0]=='Q' || S[0]=='U' || S[0]=='I' || S[0]=='N' || S[0]=='O' || S[0]=='X')
sarthak=sarthak+a;

else

}

std::cout << "SARTHAK" << std::endl;
else
std::cout << "DRAW" << std::endl;


}

return 0;


}

Can anyone tell what’s wrong
It’s running correct for every test case.

1 Like

Hi Shubh, if you see above replies, most of them are having same problem. I am not understanding why the solutions are not getting accepted while if you see my answer there is another solution I have linked which is having exact same solution and received correct answer

Yeah exactly
I saw other people’s code and all of them are same still no running, should I mail to codechef or something because I spent too much time on this one

1 Like

I dont know, if this fault of the system or the code, but whatever it is. It should be taken under notice. I will also mail the codechef team. In your code I think the mistake was in “anuradha=anuradha-b” which can even lead anuradhas points in negative. Other than that the whole solution is correct as per my logic

int sarthak = 0, annu = 0;
instead of int use long long

Ohh okay
Let me check again

Your logic is correct but you forgot to use long long.