QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641778#7781. Sheep Eat WolvesjingjingyaWA 0ms3608kbC++142.7kb2024-10-14 23:22:502024-10-14 23:22:50

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 23:22:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-10-14 23:22:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 +10;
#define int long long
#define ll int
#define double long double
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define G(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define si(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define pb push_back
#define fori(x,y) for(int i=x;i<=(int)y;++i)
#define forj(x,y) for(int j=x;j<=(int)y;++j)
const ll MOD = 998244353;
ll qpow(ll a, ll b) {
	ll res = 1, base = a;
	while (b) {
		if (b&1) res = (res*base)%MOD;
		base = (base*base)%MOD;
		b >>= 1;
	}
	return res;
}

inline ll read() {
    ll sum = 0, ff = 1; char c = getchar();
    while(c<'0' || c>'9') { if(c=='-') ff = -1; c = getchar(); }
    while(c>='0'&&c<='9') { sum = sum * 10 + c - '0'; c = getchar(); }
    return sum * ff;
}
int ls,rs,lw,rw,p,q;
int bs,bw;
signed main() {
    cin>>rs>>rw>>p>>q;
    int qrs = rs, qrw = rw, qp = p, qq = q,qbs = bs,qbw = bw;
    if(rw-p-rs>q){
        cout<<-1;
        return 0;
        
    }
    int ans = 0;
    /*
    int minn = rs/p;
    if(rs%p) minn++;
    int k = rs%p;
    k = min(k,p-k);
    */
   /*
   if(rw>rs+q){
    ans = rs/p+1;
    if(rs%p) ans++;
    cout<<2*ans -1<<'\n';
    return 0;
   }
   */
    
    while(rs>p){
        ans++;

        if(bw){
            rw +=bw;
            bw = 0;
        }
        while(bs+bw<p&&rw<rs+q){
            rs--;
            bs++;
        }
        while(rw&&rs&&bs+bw<=p-2){
            rs--;
            rw--;
            bs++;
            bw++;
        }
        while(ls+bs+q>lw+bw&&bs+bw<=p-1&&rw){
            rw--;
            bw++;
        }

        if(bs){
            ls +=bs;
            bs=0;
        }
        while(bw&&lw<ls+q){
            bw--;
            lw++;
        }
    }
    if(rs){
        ans++;
    }
    int qans = 0;
    rs = qrs, rw = qrw, p = qp, q = qq,bs = qbs,bw = qbw;
    qans+=2;
    rs -=p;
    rw -=p;
    ls +=p;
    lw +=p;
    if(rs<0||rw<0) qans = 19999;
    while(rs>p){
        qans++;

        if(bw){
            rw +=bw;
            bw = 0;
        }
        while(bs+bw<p&&rw<rs+q){
            rs--;
            bs++;
        }
        while(rw&&rs&&bs+bw<=p-2){
            rs--;
            rw--;
            bs++;
            bw++;
        }
        while(ls+bs+q>lw+bw&&bs+bw<=p-1&&rw){
            rw--;
            bw++;
        }

        if(bs){
            ls +=bs;
            bs=0;
        }
        while(bw&&lw<ls+q){
            bw--;
            lw++;
        }
    }
    if(rs){
        qans++;
    }
   // ans = min(qans,ans);
    cout<<2*ans -1<<'\n';
    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3600kb

input:

3 5 2 0

output:

3

result:

wrong answer 1st numbers differ - expected: '5', found: '3'