PROBLEM LINK:
Practice
Contest: Division 3
Contest: Division 2
Contest: Division 1
Author: Daanish Mahajan
Tester: Manan Grover
Editorialist: Vichitr Gandas
DIFFICULTY:
CAKEWALK
PREREQUISITES:
NONE
PROBLEM:
Given the time control of a chess match as a+b, determine which format of chess out of the given 4 it belongs to.
EXPLANATION
Just check what is asked.
- If a+b < 3, print 1.
- If 3 \leq a+b \leq 10, print 2.
- If 11 \leq a+b \leq 60, print 3.
- If a+b > 60, print 4.
TIME COMPLEXITY:
O(1) per test case
SOLUTIONS:
Setter's Solution
#include<bits/stdc++.h>
# define pb push_back
#define pii pair<int, int>
#define mp make_pair
# define ll long long int
using namespace std;
const string newln = "\n", space = " ";
int main()
{
int t, a, b;
cin >> t;
while(t--){
cin >> a >> b;
int time = a + b;
int ans = 4;
if(time < 3)ans = 1;
else if(time <= 10)ans = 2;
else if(time <= 60)ans = 3;
cout << ans << endl;
}
}
Tester's Solution
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
while(t--){
int a, b;
cin>>a>>b;
if(a + b < 3){
cout<<1<<"\n";
}else if(a + b <= 10){
cout<<2<<"\n";
}else if(a + b <= 60){
cout<<3<<"\n";
}else{
cout<<4<<"\n";
}
}
return 0;
}
Editorialist's Solution
/*
* @author: vichitr
* @date: 24th July 2021
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios::sync_with_stdio(0); cin.tie(0);
void solve() {
int a, b; cin >> a >> b;
if (a + b < 3) cout << "1\n";
else if (a + b <= 10) cout << "2\n";
else if (a + b <= 60) cout << "3\n";
else cout << "4\n";
}
signed main() {
fast;
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t = 1;
cin >> t;
for (int tt = 1; tt <= t; tt++) {
// cout << "Case #" << tt << ": ";
solve();
}
return 0;
}
VIDEO EDITORIAL:
If you have other approaches or solutions, let’s discuss in comments.If you have other approaches or solutions, let’s discuss in comments.