ECJN204 - Editorial

PROBLEM LINK:

Encoding June’20 Contest
Problem

Author: shrivas7
Tester: sandeep1103
Editorialist: shrivas7

DIFFICULTY:

EASY

EXPLANATION:

We need to have three variables which will be used to calculate the points . For each round alter the points as per their moves. The solution is to implement the points distribution rules by using various possible cases .
Two approaches to the problems are published below ,refer them for better clarity.

SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
# define ll long long
using namespace std;
 
 
void calc(char a,char b,ll &p,ll &q)
{
	if(a=='R'&&b=='P')
	{
		p--;
		q++;
	}
	else if(a=='R'&&b=='S')
	{
		p++;
		q--;
	}
	else if(a=='P'&&b=='S')
	{
		p--;
		q++;
	}
	else if(a=='P'&&b=='R')
	{
		p++;
		q--;
	}
	else if(a=='S'&&b=='R')
	{
		p--;
		q++;
	}
	else if(a=='S'&&b=='P')
	{
		p++;
		q--;
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,n,chef,chefu,chefina;;
	char a,b,c;
	cin>>t;
	while(t--)
	{
		cin>>n;
		chef=chefu=chefina=0;
		while(n--)
		{
			cin>>a>>b>>c;
			calc(a,b,chef,chefu);
			calc(b,c,chefu,chefina);
			calc(c,a,chefina,chef);
		
			
		}
		cout<<chef<<" "<<chefu<<" "<<chefina<<endl;
	}
	
	return 0;
} 
Tester's Solution
#include <bits/stdc++.h>
#define ll long long int
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define scanarr(a,b,c) for( i=b;i<c;i++)cin>>a[i]
#define showarr(a,b,c) for( i=b;i<c;i++)cout<<a[i]<<' '
#define ln cout<<'\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define MAX 100005
using namespace std;
////////////////////////////////////////////////////////////////CODE STARTS HERE////////////////////////////////////////////////////////////////
unordered_map <char, char> win, lose;
 
void solve(){
 
    ll n, i, j;
 
    cin >> n;
    char m1, m2, m3;
    ll chef = 0, chefu = 0, chefina = 0;
    unordered_map <char, int> moves;
 
    for(i = 0; i < n; ++i){
 
        moves['R'] = moves['P'] = moves['S'] = 0;
 
        cin >> m1 >> m2 >> m3;
        moves[m1]++;
        moves[m2]++;
        moves[m3]++;
 
        chef += moves[win[m1]];
        chef -= moves[lose[m1]];
 
        chefu += moves[win[m2]];
        chefu -= moves[lose[m2]];
 
        chefina += moves[win[m3]];
        chefina -= moves[lose[m3]];
 
    }
    cout << chef << " " << " " << chefu << " " << chefina << endl; 
}
    
 
int main(){
 
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    win['R'] = 'S'; lose['R'] = 'P';
 
    win['P'] = 'R'; lose['P'] = 'S';
 
    win['S'] = 'P'; lose['S'] = 'R';
 
    int t;
    cin >> t;
 
    while(t--)
        solve();
}