Introduction
The contest can be found here
This is an unofficial editorial and I am no way associated to Vplanet!
. Also this is my first day at code forces and my first ever blog on first code forces , and I have tried to replicate many editorial blogs as far as possible, but if I have made any mistake , please do let me know :D
Problem A Key Races
So How do we calculate the time taken by a person. The person takes v seconds to type a character. And he is supposed to type s characters. He also faces a lag of t seconds 2 times , In the beginning while loading and second time when the site gets his data. So the formula to calculate the time would be:
Time = (v*s)+(2*t)
So now we can calculate the time by both participants and compare thus printing the output accordingly
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define debug(x) cout << (#x) << "'s value is " << (x)<<newl
/* __
/ / ___ ____ ___ ____ ____
/ / / _ \/ __ `__ \/ __ \/ __ \
/ /___/ __/ / / / / / /_/ / / / / is the best!!!
/_____/\___/_/ /_/ /_/\____/_/ /_/
*/
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
// Main code starts here
void answer(int i){
int s,v1,v2,t1,t2;
cin>>s>>v1>>v2>>t1>>t2;
int participant1 = (s*v1)+(2*t1);
int participant2 = (s*v2)+(2*t2);
if(participant1<participant2){
cout<<"First"<<newl;
}
if(participant2<participant1){
cout<<"Second"<<newl;
}
if(participant1==participant2){
cout<<"Friendship"<<newl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}
____________________________________________________________________________________
Problem B — Fafa and the Gates
Lets plot the x=y graph and check how it looks like
Now we will notice that the person will be in the first kingdom if the x cordinate is greater than the y cordinate and is in the second kingdom when x cordinate is greater than y. So you can make a vector of at a time where the person is ie. kingdom 1 or kingdom 2. Tehn you can check the number of times he changes from one to two or vice versa.
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define debug(x) cout << (#x) << "'s value is " << (x)<<newl
/* __
/ / ___ ____ ___ ____ ____
/ / / _ \/ __ `__ \/ __ \/ __ \
/ /___/ __/ / / / / / /_/ / / / / is the best!!!
/_____/\___/_/ /_/ /_/\____/_/ /_/
*/
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
// Main code starts here
void answer(int i){
int n;
cin>>n;
string s;
cin>>s;
vector<int> position;
int x =0;
int y = 0;
for(int i = 0;i<s.length();i++){
char curr = s[i];
if(curr=='U'){
y = y+1;
}
if(curr=='R'){
x = x+1;
}
if(x>y){
position.push_back(1);
}
if(y>x){
position.push_back(2);
}
}
int answer = 0;
auto lol = position.begin();
int curr = *lol;
int bum;
for(auto it=position.begin();it!=position.end();it++){
bum = *it;
if(bum!=curr){
answer++;
}
curr = bum;
}
cout<<answer;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}
____________________________________________________________________________________
Problem C — Bark to Unlock
So the dog will obviously unlock if he speaks that exact same word, so that can be a preliminary test. Also we notice that the password has only letters . So we can traverse through the words the enemy can speak and check if the first letter of the password is the last letter of one of the word the enemy can speak and if the last letter of the password is the first letter of one of the word , so he can speak these words simultaneously and pronounce the word. Also as we notice in the third testcase how speaking the word reverse it . So check if the enemy can speak the reverse word as well.
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define debug(x) cout << (#x) << "'s value is " << (x)<<newl
/* __
/ / ___ ____ ___ ____ ____
/ / / _ \/ __ `__ \/ __ \/ __ \
/ /___/ __/ / / / / / /_/ / / / / is the best!!!
/_____/\___/_/ /_/ /_/\____/_/ /_/
*/
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
// Main code starts here
bool checkreverse(string curr, string password){
if(curr[1]==password[0] && curr[0]==password[1]){
return true;
}
return false;
}
void answer(int i){
string password;
cin>>password;
int n;
cin>>n;
string arr[n];
for(int i = 0;i<n;i++){
cin>>arr[i];
if(arr[i]==password || checkreverse(arr[i],password)==true){
cout<<"YES";
return;
}
}
bool firstfound = false;
bool lastfound = false;
for(string item:arr){
char maybe_first = item[1];
char maybe_last = item[0];
if(maybe_first==password[0]){
firstfound = true;
}
if(maybe_last==password[1]){
lastfound = true;
}
}
if(firstfound==true && lastfound==true){
cout<<"YES";
}
else{
cout<<"NO";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}
____________________________________________________________________________________
D. Race Against Time
In this problem fuirst we need to mark all the positoon of the hands. then from the current time we can either go back or front , If in this process we meet any hand , then we cannot use that method. So if either up is possible or down is possible , print Yes or print No
Solution#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
const char newl='\n';
#define ll long long
#define debug(x) cout << (#x) << "'s value is " << (x)<<newl
/* __
/ / ___ ____ ___ ____ ____
/ / / _ \/ __ `__ \/ __ \/ __ \
/ /___/ __/ / / / / / /_/ / / / / is the best!!!
/_____/\___/_/ /_/ /_/\____/_/ /_/
*/
const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
// Main code starts here
bool checkreverse(string curr, string password){
if(curr[1]==password[0] && curr[0]==password[1]){
return true;
}
return false;
}
void answer(int i){
int H, M, S, t1, t2;
cin>>H>>M>>S>>t1>>t2;
if (t1 == 12){
t1 = 0;
}
if (t2 == 12){
t2 = 0;
}
t1 *= 5;
t2 *= 5;
if (H == 12){
H = 0;
}
H = (H * 5 + M / 12);
if (t1 > t2){
swap(t1, t2);
}
bool up = false;
bool down = false;
if (t1 <= H && H < t2){
up = true;
}
else{
down = true;
}
if (t1 <= M && M < t2){
up = true;
}
else{
down = true;
}
if (t1 <= S && S <= t2){
up = true;
}
else{
down = true;
}
if (!up || !down){
cout<<"YES"<<newl;
}
else{
cout<<"NO"<<newl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
//cin>>test;
int curr = 1;
while(test--){
answer(curr);
curr++;
}
}
____________________________________________________________________________________