TRANSFORM - Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Kanhaiya Mohan
Tester: Harris Leung
Editorialist: Trung Dang

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Mario transforms each time he eats a mushroom as follows:

  • If he is currently small, he turns normal.
  • If he is currently normal, he turns huge.
  • If he is currently huge, he turns small.

Given that Mario was initially normal, find his size after eating X mushrooms.

EXPLANATION:

Notice that Mario’s states are arranged in a cycle of size 3. Therefore it is only necessary to do X \mod 3 transformations to achieve at his final state.

TIME COMPLEXITY:

Time complexity is O(1) for each test case.

SOLUTION:

Setter's Solution
#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
	    int x;
	    cin>>x;
	    x %= 3;
	    if(x==0) cout<<"NOrMAL";
	    else if(x==1) cout<<"HUGE";
	    else cout<<"SMalL";
	    cout<<endl;
	}
	return 0;
}
Tester's Solution
#include<bits/stdc++.h>
using namespace std;
// -------------------- Input Checker Start --------------------

long long readInt(long long l, long long r, char endd)
{
    long long x = 0;
    int cnt = 0, 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(false);
            }
            return x;
        }
        else
        {
            assert(false);
        }
    }
}

string readString(int l, int r, char endd)
{
    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) { return readInt(l, r, ' '); }
long long readIntLn(long long l, long long r) { return readInt(l, r, '\n'); }
string readStringLn(int l, int r) { return readString(l, r, '\n'); }
string readStringSp(int l, int r) { return readString(l, r, ' '); }
void readEOF() { assert(getchar() == EOF); }

vector<int> readVectorInt(int n, long long l, long long r)
{
    vector<int> a(n);
    for(int i = 0; i < n - 1; i++)
        a[i] = readIntSp(l, r);
    a[n - 1] = readIntLn(l, r);
    return a;
}

// -------------------- Input Checker End --------------------
string s[3]={"NORMAL","HUGE","SMALL"};
void solve(){
	int n;n=readInt(1,100,'\n');
	cout << s[n%3] << '\n';
}
int main(){
	ios::sync_with_stdio(false);
	int t;t=readInt(1,100,'\n');while(t--) solve();readEOF();
}
Editorialist's Solution
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<string> states = {"normal", "huge", "small"};
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        cout << states[n % 3] << '\n';
    }
}