QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661081 | #7781. Sheep Eat Wolves | ruoye123456 | WA | 0ms | 3668kb | C++20 | 2.3kb | 2024-10-20 14:36:43 | 2024-10-20 14:36:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline void divide() {sort(vx.begin(),vx.end());vx.erase(unique(vx.begin(),vx.end()),vx.end());}
//inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
inline ll Lsqrt(ll x) { ll L = 1,R = 2e9;while(L + 1 < R){ll M = (L+R)/2;if(M*M <= x) L = M;else R = M;}return L;}
void solve()
{
int x,y,p,q;
cin>>x>>y>>p>>q;
if(y<=x+q)
{
ll ans=0;
if(x<=p) ans=1;
else{
int qu = (x-(y-q));
ans+=qu/q*2;
x-=qu/q*2;
y-=qu/q*2;
int left = qu%(qu/q*q),pp;
x-=left;
if(p>x)
{
x=0;
ans++;
}else{
pp-=left;
x-=pp/2;
y-=pp/2;
ans+=2;
}
if(x>p)
{
x-=p;
ans+=(x+p-1)/p;
}
if(x>0)
ans+=1;
}
cout<<ans<<endl;
}else{
long long ans=0;
if(y-p>x+q)
{
cout<<-1<<endl;
return ;
}
ll pp =p;
ll qu = max(0,(y-(x+q))),rightw=0,righty=0;
pp -= qu;
rightw+=qu;
int cnt=0;
while(x>0&&pp>=2)
{
if(++cnt>=101) break;
x-=1;
y-=1;
rightw+=1;
righty+=1;
pp-=2;
}
ans+=2;
if(righty)
{
pp=q-qu;
}else{
x-=p/2;
y-=p/2;
rightw+=p/2;
righty+=p/2;
pp =p-max(rightw-righty+q,0ll);
ans+=2;
}
if(x>p)
{ x-=p;
ans+=(x+pp-1)/pp;
}
ans+=1;
cout<<ans<<endl;
}
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0);
int T=1;
//cin>>T;
while(T--)
{
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3668kb
input:
3 3 1 1
output:
5
result:
wrong answer 1st numbers differ - expected: '7', found: '5'