QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#634394 | #7781. Sheep Eat Wolves | the_fool# | WA | 1ms | 3724kb | C++20 | 1.7kb | 2024-10-12 17:13:08 | 2024-10-12 17:13:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ll = long long;
int x,y,p,q;
void solve() {
cin>>x>>y>>p>>q;
int x1=0,y1=0,ans=0;
while(x)
{
ans++;
if(y1-x1>q&&x1)
{
ans=-1;
break;
}
if(x<=p)break;
if(y-x>q&&ans!=1)
{
ans=-1;
break;
}
int t=x+q-y,t1=0;
if(t>=0)
{
if(t>=p)t=p;
else t1=(p-t)/2;
if(t==0&&t1==0) {
if(y-x-1<=q) {
x-=1;
x1+=1;
}
else {
y-=1;
y1+=1;
}
}
x-=t+t1;
y-=t1;
x1+=t+t1;
y1+=t1;
if(x<=p)y1-=p;
}
else
{
t=-t;
if(t>=p)t=p;
else t1=(p-t)/2;
if(t==0&&t1==0)
{
if(y-x-1<=q) {
x-=1;
x1+=1;
}
else {
y-=1;
y1+=1;
}
}
x-=t1;
y-=t+t1;
x1+=t1;
y1+=t+t1;
if(x<=p)y1-=p;
}
}
if(ans==-1)cout<<ans<<endl;
else cout<<ans+ans-1<<endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef Debug
assert(freopen("in.txt", "r", stdin));
assert(freopen("out.txt", "w", stdout));
#endif
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3672kb
input:
1 1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3584kb
input:
3 3 1 1
output:
5
result:
wrong answer 1st numbers differ - expected: '7', found: '5'