# HIRETEST - Editorial

Author: Akash Bhalotia
Tester: Felipe Mota
Editorialist: Vichitr Gandas

SIMPLE

None

# PROBLEM:

Given N candidates appeared for the test, and each of them faced M problems. Each problem was either unsolved by a candidate (denoted by ‘U’), solved partially (denoted by ‘P’), or solved completely (denoted by ‘F’).

To pass the test, each candidate needs to either solve X or more problems completely, or solve (X−1) problems completely, and Y or more problems partially. Check if given candidates passed the test or not.

# QUICK EXPLANATION:

Just check the conditions as specified in the problem.

# EXPLANATION:

For a candidate, lets denote the count of problems solved completely by C_F, solved partially by C_P. Now check if (C_F \geq X) or (C_F \geq X-1 and C_P \geq Y).

# TIME COMPLEXITY:

O(N * M) if there are N candidates and M problems as we need to iterate through each candidate and find the count of problems solved full, solved partial.

# SOLUTIONS:

Setter's Solution
``````//created by Whiplash99
import java.io.*;
import java.util.*;
class A
{
public static void main(String[] args) throws Exception
{

int i,N;

StringBuilder sb=new StringBuilder();

while (T-->0)
{
N=Integer.parseInt(s[0]);
int M=Integer.parseInt(s[1]);

int X=Integer.parseInt(s[0]);
int Y=Integer.parseInt(s[1]);

for(i=0;i<N;i++)
{
int full=0,partial=0;

for(char c:ch)
{
if(c=='F') full++;
else if(c=='P') partial++;
}

if(full>=X||(full==X-1&&partial>=Y)) sb.append(1);
else sb.append(0);
}

sb.append("\n");
}
System.out.println(sb);
}
}
``````
Tester's Solution
``````#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
long long readInt(long long l,long long r,char endd){
long long x=0;
int cnt=0;
int fi=-1;
bool is_neg=false;
while(true){
char g=getchar();
if(g=='-'){
assert(fi==-1);
is_neg=true;
continue;
}
if('0'<=g && g<='9'){
x*=10;
x+=g-'0';
if(cnt==0){
fi=g-'0';
}
cnt++;
assert(fi!=0 || cnt==1);
assert(fi!=0 || is_neg==false);

assert(!(cnt>19 || ( cnt==19 && fi>1) ));
} else if(g==endd){
if(is_neg){
x= -x;
}
assert(l<=x && x<=r);
return x;
} else {
assert(false);
}
}
}
string ret="";
int cnt=0;
while(true){
char g=getchar();
assert(g!=-1);
if(g==endd){
break;
}
cnt++;
ret+=g;
}
assert(l<=cnt && cnt<=r);
return ret;
}
long long readIntSp(long long l,long long r){
}
long long readIntLn(long long l,long long r){
}
}
}
long long TEN(int p){ long long r = 1; while(p--) r *= 10; return r; }
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
while(t--){
assert((x - 1) + y <= m);
for(int i = 0; i < n; i++){
for(auto & c : s)
assert(c == 'U' || c == 'P' || c == 'F');
int f = count(s.begin(), s.end(), 'F');
int p = count(s.begin(), s.end(), 'P');
int has = 0;
if(f >= x) has = 1;
else if(f == x - 1 && p >= y) has = 1;
cout << has;
}
cout << '\n';
}
assert(getchar() == -1);
return 0;
}
``````
Editorialist's Solution
``````/***************************************************

@author: vichitr
Compiled On: 23 Apr 2021

*****************************************************/
#include<bits/stdc++.h>
using namespace std;

void solve(){
int n, m; cin >> n >> m;
int x, y; cin >> x >> y;
for(int i=0;i<n;i++){
int p = 0, f = 0;
string c; cin >> c;
for(char j: c){
if(j == 'P')
p++;
if(j == 'F')
f++;
}
if(f >= x or (f == x - 1 and p >= y))
cout <<"1";
else
cout <<"0";
}
cout << '\n';
}

signed main()
{
int t=1;
cin >> t;
for(int i=1;i<=t;i++)
{
solve();
}
return 0;
}
``````

In this problem, my answer runs fine with the test cases but when submitting it says WA, can anyone share the whole test case used for checking this problem.

Im including my c code, anyone can run and check it, also please see if it takes the input correctly, i dont see any problem on that side but still.

heres the code,
#include<stdio.h>

int main()

{

int t,n,m,x,y,count=0;

scanf("%d\n",&t);

int arr1[10000];

for (int s=0;s<t;s++)

{

scanf("%d %d\n",&n,&m);

scanf("%d %d\n",&x,&y);

char arr[m];

``````for(int i=1;i<=n;i++){

int X=0,Y=0;

scanf("%[^\n]%*c", arr);

// printf("%s",arr);

for(int k=0;k<m;k++){

if(arr[k]=='U'){}

else if(arr[k]=='P'){

Y++;

}

else X++;

}

if((X>=x)||((X>=(x-1)&&Y>=y)))

{

arr1[i+count]=1;

}
``````

else {arr1[i+count]=0;}

}

count=count+(n+1);

arr1[count]=-1;

}

``````    for(int d=1;d<=count;d++){

if(arr1[d]==-1){

printf("\n");

}

else{

printf("%d",arr1[d]);

}

}
``````

return 0;

}

My code ran for all the test cases i could think of but it still gave WA. Can someone please point out my mistake?

#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n, m;
cin >> n >> m;
int x, y;
cin >> x >> y;
for (int i = 1; i <= n; i++) {
char a[m];
for (int i = 1; i <= m; i++)
cin >> a[i];

``````		int solved = 0, unsolved = 0, partially = 0;
for (int i = 1; i <= m; i++) {
if (a[i] == 'F') {
solved++;
}
else if (a[i] == 'U') {
unsolved++;
}
else if (a[i] == 'P') {
partially++;
}

}

if (solved == x ) {
cout << 1;
}
else if (partially == y and solved == x - 1) {
cout << 1;
}
else {
cout << 0;
}

}
cout << endl;

}

return 0;
``````

}

What if `solved > x`?

1 Like

Its wrong for below cases —

2. partially > y and solved = x-1, answer is 1 but your solution gives 0.

Why incrementing count by n+1? It should be incremented by 1.

Its n+1 because i’m storing all the results in a linear array and after every n candidates results i add a -1 at the n+1 index so i can add a newline when the for loop encounters it.

I tried it with +1 as well instead of n+1 but it still doesnt work.
Would be great if u could share the test cases u used to check it in codechef.

Thanks a lot found out my mistake.

Got it!..tysm

Here is my solution which is running fine for the test cases but still it is showing WA … could anyone pls point out the mistake. Thanks in advance.
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t>0){
int n,m;
cin>>n>>m;
int x,y;
cin>>x>>y;
int extra=n; // just a variable to run the below loop
string ans;
while(extra>0){
string str;
cin>>str;
int nof=0;
int nop=0;

``````	        for(int i=0;i<sizeof(str);i++){
char ch=str[i];
if(ch=='F'){
nof++;
}else if(ch=='P'){
nop++;
}
}

if(nof>=x || ( nof==x-1 && nop>=y ) ){
ans+='1';
}else{
ans+='0';
}

extra--;
}
cout<<ans<<endl;
t--;
}
return 0;
``````

}

my code is crct for all the test cases I can think of… Can anyone plss point out y does it show WA still.

#include <stdio.h>

int main(void) {
int t,n,m,x,y;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
scanf("%d",&n);
scanf("%d",&m);
scanf("%d",&x);
scanf("%d",&y);
int a[n];
for(int j=0;j<n;j++)
{
char s[m];
scanf("%s",&s);
int f=0,p=0;
for(int k=0;k<m;k++)
{
if(s[k]==‘F’ || s[k]==‘f’)
f++;
else if(s[k]==‘P’ || s[k]==‘p’)
p++;
}
if((f>=x) || (f==x-1 && p>=y))
a[j]=1;
else
a[j]=0;
}
for(int j=0;j<n;j++)
{
printf("%d",a[j]);
}
printf("\n");
}
return 0;
}

my code passed the test cases but failed during the submission, can anyone help me with this problem ?

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
short t=sc.nextShort();
while(t>0)
{
t–;
short n,m,x,y,a=0,b=0;
n=sc.nextShort();
m=sc.nextShort();
x=sc.nextShort();
y=sc.nextShort();
String[]s=new String[n];
for(short i=0;i<s.length;i++)
s[i]=sc.next();
for(short i=0;i<s.length;i++)
{
a=0;b=0;
for(short j=0;j<s[i].length();j++)
{
if(s[i].charAt(j)==‘F’)
a++;//completely correct
else if(s[i].charAt(j)==‘P’)
b++;
}
if((a>=x || (x-1)==a) && ( b>=y ))// passsing condition
System.out.print(1);
else
System.out.print(0);
}
System.out.println();

``````    }
}
``````

}

Change this to

``````if((a >= x) || ((x - 1 == a) && (b >= y)))
``````

This should work