1461E - Water Level - CodeForces Solution


brute force graphs greedy implementation math *2200

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PII pair<ll,ll>
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof a)
#define endl '\n'
const ll N=1e6+5;
const ll eps=1e-8;
const ll mod=998244353;
bool cmp(ll a,ll b){return a>b;}
ll lowbit(ll x){return x&-x;}
ll Abs(ll x){return x>0?x:-x;}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1,y=0;return a;}ll d=exgcd(b,a%b,y,x);y-=a/b*x;return d;}
ll ksm(ll a,ll b,ll c){ll sum=1;while(b){if(b&1)sum=sum*a%c;a=a*a%c;b>>=1;}return sum;}
//ll h[N],e[N*2],ne[N*2],w[N*2],idx;void add(ll a,ll b,ll c){e[idx]=b,ne[idx]=h[a],h[a]=idx,w[idx++]=c;}
//ll fa[N],siz[N];ll ifind(ll x){return x==fa[x]?x:fa[x]=ifind(fa[x]);}
ll n,m;
void solve()///x==y就判断上下界出不出界
///x>y-->第一天能加就加,有可能加不上,然后喝一个x,之后就计算能撑几天
///x<y-->第一天能加就加,有可能加不上,有可能喝一口就没了,之后就是喝几天加一天,判断循环
{
    map<ll,ll> dl;
    ll k,l,r,t,x,y;
    cin>>k>>l>>r>>t>>x>>y;///用x加y
    if(x==y)///三种情况讨论
    {
        if(k-x>=l || k+y<=r) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(x>y)
    {
        ll down=(x-y);
        ll now=0;
        if(k+y<=r) k+=y;///第一天特判
        if(k-x>=l)
        {
            k-=x;///第一天喝水
            now++;
            now+=(k-l)/down;///之后按照这个操作能坚持几天
        }
        if(now>=t) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else if(x<y)
    {
        ll now=0;
        while(now<t)
        {
            if(k+y<=r) k+=y;
            ll pp=(k-l)/x;
            if(dl[k]==1)
            {
                cout<<"Yes"<<endl;
                return ;
            }
            if(pp==0)
            {
                cout<<"No"<<endl;return ;
            }
            now+=pp;
            dl[k]=1;
            k-=pp*x;
        }
        cout<<"Yes"<<endl;
    }
}
int main(){
    ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
    ll tt = 1 ;
    //cin>>tt;
    while(tt--) solve();
}

    			 	 	  				   						   		


Comments

Submit
0 Comments
More Questions

1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza
731A - Night at the Museum
742A - Arpa’s hard exam and Mehrdad’s naive cheat
1492A - Three swimmers
1360E - Polygon
1517D - Explorer Space
1230B - Ania and Minimizing
1201A - Important Exam
676A - Nicholas and Permutation
431A - Black Square
474B - Worms
987B - High School Become Human
1223A - CME
1658B - Marin and Anti-coprime Permutation
14B - Young Photographer
143A - Help Vasilisa the Wise 2
320A - Magic Numbers
1658A - Marin and Photoshoot
514A - Chewbaсca and Number
382A - Ksenia and Pan Scales
734B - Anton and Digits
1080A - Petya and Origami
1642D - Repetitions Decoding
1440A - Buy the String
1658F - Juju and Binary String
478A - Initial Bet