PROBLEM LINK: Frog Puddle | CodeChef
Problem Code: Frog Puddle | CodeChef
Practice: CodeChef | Competitive Programming | Participate & Learn | CodeChef
Contest : Carnival Finale Coding Competition | CodeChef
Author: Codechef Adgitm Chapter : atharv_mm404 | CodeChef User Profile for Atharv Karbhari | CodeChef
Tester: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
Editorialist: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
DIFFICULTY:
Hard
PROBLEM:
You are a frog that lives in a rainforest surrounded by swamps and puddles. All of your friends notice a giant snake lurking by the lake, and you are given the task to guide your friends to the nearest lake.
Unfortunately, the rain has made things worse. The path to the nearest lake is filled with holes that end up in mushy soil which can trap you and your friends. The group decides to jump through the path to the nearest lake by following a specific rule. All of the frogs would make jumps in combinations of two given numbers.
Thankfully, the lake is straight ahead, and you were aware enough to notice the location of the holes. Given that your frog friends are stupid, and the length of jumps J1,J2 they can take, find out whether all of your friends would certainly make their way towards the pond.
NOTE: The frogs being frogs, are capable of jumping backward.
EXPLANATION:
Use flag and conditions.
SOLUTION:
C++:
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{FAST;ll t=1,n,i,j,k,len,x,y,z,c,f,flag,p,q,mx,mn,l,r,sum,ans,tmp,it,pos,avg,m,cnt;
string s;char ch;vll v;vpll vec;unordered_map<ll,ll> mappu;pair<ll,ll> pr;
cin>>t;while(t–)
{
f=0;sum=0;flag=0;ans=0;cnt=0;v.clear();mappu.clear();vec.clear();
cin>>n;
x=1;
while(cin>>x)
{
if(x==-1) break;
v.pb(x);
}
cin>>x>>y;
for(auto it:v)
{
if(it%x==0 or it%y==0) flag=1;
}
if(flag) cout<<"Dead"<<ln;
else cout<<"Alive"<<ln;
}
return 0;
}