 FRGAME - Editorial

Game between friends:

Practice

Code Drive Contest Division 1

Code Drive Contest Division 2

Code Drive Contest Division 3

Author: Sobhagya Singh Dewal

Tester: Lavish Gupta , Takuki Kurokawa

CAKEWALK

Implementation

PROBLEM:

Nitin and Sobhagya were playing a game with coins. If Sobhagya has more coins then he is winning, otherwise Nitin is winning. Note that this means if both Nitin and Sobhagya have the same number of coins, then Nitin is winning.

Initially Nitin has A coins while Sobhagya has B coins. Then Ritik came and gave his C coins to the player who is not winning currently, after which Satyarth came and repeated the same process (gave his D coins to the player who is not winning currently).

Find the final winner of the game.

QUICK EXPLANATION:

At each point when Ritik and Satyarth will join we will just increase coins of current losing player.

EXPLANATION:

Initially we know that Nitin has A coins while Sobhagya has B coins, now Ritik will come with his C coins and give them to current losing player. The current losing is player is Nitin if A<B or Sobhagya if A\geq B, So Ritik will just check current losing player and give his C coins to the losing player, and now losing player will have additional C coins. The same process Satyarth will repeat and give his D coins to the losing player after Ritik’s turn. At the end if A<B then winner is Sobhagya or else winner is Nitin. Where A and B are final coins of Nitin and Sobhagya after Ritik and Satyarth’s turn.
Time Complexity: O(1) for each test case.

SOLUTIONS:

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

void myfun()
{
int nitin,sobhagya,ritik,satyarth;
cin>>nitin>>sobhagya>>ritik>>satyarth;
if(sobhagya>nitin)
{
nitin+=ritik;
}
else
{
sobhagya+=ritik;
}
if(sobhagya>nitin)
{
nitin+=satyarth;
}
else
{
sobhagya+=satyarth;
}
if(sobhagya>nitin)
{
cout<<"S\n";
}
else
{
cout<<"N\n";
}
}

int main()
{
int t=1;
cin>>t;
while(t--)
myfun();
return 0;
}
Tester's (Lavish Gupta) Solution
// O(2^20)
#include <bits/stdc++.h>
using namespace std;
#define ll long long

/*
------------------------Input Checker----------------------------------
*/

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;
}

if(!(l <= x && x <= r))
{
cerr << l << ' ' << r << ' ' << x << '\n';
assert(1 == 0);
}

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){
}
}
}

/*
------------------------Main code starts here----------------------------------
*/

const int MAX_T = 1000;
const int MAX_N = 1000000;
const int MAX_SUM_N = 100000;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int sum_n = 0;
int max_n = 0;
int yess = 0;
int nos = 0;
int total_ops = 0;
ll z = 998244353;
ll dp ;

void solve()
{
int a = readIntSp(1 , MAX_N) ;
int b = readIntSp(1 , MAX_N) ;
int c = readIntSp(1 , MAX_N) ;
int d = readIntLn(1 , MAX_N) ;

if(a < b)
a += c ;
else
b += c ;

if(a < b)
a += d ;
else
b += d ;

if(a < b)
cout << "S" << '\n' ;
else
cout << "N" << '\n' ;
return ;
}

signed main()
{
//fast;
#ifndef ONLINE_JUDGE
freopen("inputf.txt" , "r" , stdin) ;
freopen("outputf.txt" , "w" , stdout) ;
freopen("error.txt" , "w" , stderr) ;
#endif

int t = 1;

for(int i=1;i<=t;i++)
{
solve() ;
}

assert(getchar() == -1);
// assert(sum_n <= MAX_SUM_N);

cerr<<"SUCCESS\n";
cerr<<"Tests : " << t << '\n';
// cerr<<"Sum of lengths : " << sum_n << '\n';
// cerr<<"Maximum length : " << max_n << '\n';
// cerr<<"Total operations : " << total_ops << '\n';
// cerr<<"Answered yes : " << yess << '\n';
// cerr<<"Answered no : " << nos << '\n';
}
Tester's (Takuki Kurokawa) Solution
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a < b) {
a += c;
} else {
b += c;
}
if (a < b) {
a += d;
} else {
b += d;
}
cout << (a < b ? "S" : "N") << '\n';
}
return 0;
}