QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660830#7781. Sheep Eat WolvesabsabsWA 0ms3676kbC++233.3kb2024-10-20 13:33:302024-10-20 13:33:34

Judging History

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

  • [2024-10-20 13:33:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3676kb
  • [2024-10-20 13:33:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ull unsigned long long
#define ms(x, y) memset(x, y, sizeof x);
#define debug(x) cout << #x << " = " << x << endl;
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define fre                           \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const double esp = 1e-6;
const ull MOD1 = 1610612741;
const ull MOD2 = 805306457;
const ull BASE1 = 1331;
const ull BASE2 = 131;
#define pre(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
char *p1, *p2, buf[100000]; // 快读和同步流二者只能选一个
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
int read()
{
	int x = 0, f = 1;
	char ch = nc();
	while (ch < 48 || ch > 57)
	{
		if (ch == '-')
			f = -1;
		ch = nc();
	}
	while (ch >= 48 && ch <= 57)
		x = x * 10 + ch - 48, ch = nc();
	return x * f;
}
void write(int x)
{
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}
void solve()
{
	int x,y,p,q;
    cin>>x>>y>>p>>q;
    if(q >= y)
    {
        cout << (x + p - 1) / p * 2 - 1 << endl;
        return ;
    }
    if(p == 1)
    {
        if(y > x + q + 1)
            cout << -1 << endl;
        else if(y > x + q)
            cout << 2 *(y+x)-1;
        else{//x + q >y
            // cout << x+q-y << endl;
            int ans = (x+q-y) * 2;
            ans += (x-(x+q-y)-1)*4+1;
            cout << ans << endl;
        }
        return ;
    }
    int sum=0;
    int tot1=x,tot2=y;
    while(tot1){
        // cout << tot1 << " " << tot2   << endl;
        sum++;
        int now=p;
        if(tot1<=now){
            break;
        }
        if(x-tot1+q<y-tot2 && x-tot1){
            // cout << 1 << endl;
            // cout << y-tot2-x+tot1-q << endl;
            // return ;
            tot2 += y-tot2-x+tot1-q;
            // return;
        }
        if(tot2-q>tot1){
            if(now>=(tot2-q-tot1)){
                now-=tot2-q-tot1;
                tot2-=tot2-q-tot1;
                tot1-=now/2;
                tot2-=now/2;
                if(now&1)tot2--;
            }
            else {
                cout<<-1<<endl;
                return;
            }
        }else {//yang
            if(now>=tot1-tot2+q){
                now-=tot1-tot2+q;
                tot1-=tot1-tot2+q;
                tot1-=now/2;
                tot2-=now/2;
            }else {
                tot1-=now;
                continue;
            }
        }
        sum ++;
    }
    cout<<sum<<endl;
}
// #define LOCAL
signed main()
{
	ios
	// fre
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	auto start = std::chrono::high_resolution_clock::now();
#endif
	
	int t = 1;
	// cin >> t;
	while (t--)
		solve();
	
#ifdef LOCAL
	auto end = std::chrono::high_resolution_clock::now();
	cout << "Execution time: "
	<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
	<< " ms" << '\n';
#endif
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

3 3 1 1

output:

7

result:

ok 1 number(s): "7"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

3 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

10 9 1 10

output:

19

result:

ok 1 number(s): "19"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

15 20 2 5

output:

27

result:

ok 1 number(s): "27"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

18 40 16 7

output:

5

result:

ok 1 number(s): "5"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

60 60 8 1

output:

27

result:

ok 1 number(s): "27"

Test #11:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

60 60 8 4

output:

27

result:

ok 1 number(s): "27"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

60 60 8 8

output:

25

result:

ok 1 number(s): "25"

Test #13:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

60 60 16 1

output:

13

result:

ok 1 number(s): "13"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

60 60 16 8

output:

11

result:

ok 1 number(s): "11"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

60 60 16 16

output:

11

result:

ok 1 number(s): "11"

Test #16:

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

input:

60 60 16 24

output:

8

result:

wrong answer 1st numbers differ - expected: '9', found: '8'