QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#821902#9061. Streets BehindWeaRD276#TL 43ms3644kbC++201.2kb2024-12-19 19:29:362024-12-19 19:29:42

Judging History

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

  • [2024-12-19 19:29:42]
  • 评测
  • 测评结果:TL
  • 用时:43ms
  • 内存:3644kb
  • [2024-12-19 19:29:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef double db;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;


int solve()
{
	ll n, k, a, b;
	if (!(cin >> n >> k >> a >> b))
		return 1;
	
	if (n * (b - a) < a)
	{
		cout << "-1\n";
		return 0;
	}
	
	int ans = 0;
	while (k)
	{
		ans++;
		ll y = (n * (b - a)) / a;
		//cerr << "y = " << y << '\n';
		if (y == 0)
		{
			cout << "-1\n";
			return 0;
		}
		//y = abs(y);
		k -= y;
		n += y;
		k = max(0LL, k);
	}
	
	cout << ans << '\n';
	
	return 0;
}

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int TET = 1e9;
	cin >> TET;
	for (int i = 1; i <= TET; i++)
	{
		if (solve())
		{
			break;
		}
		#ifdef ONPC
			cerr << "_____________________________\n";
		#endif
	}
	#ifdef ONPC
		cerr << "\nfinished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
	#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
9 5 5 6
2 7 1 8
3 4 1 5

output:

3
1
1

result:

ok 3 lines

Test #2:

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

input:

54
1 1 1 1
1 1 1 2
1 1 1 3
1 1 2 2
1 1 2 3
1 1 3 3
1 2 1 1
1 2 1 2
1 2 1 3
1 2 2 2
1 2 2 3
1 2 3 3
1 3 1 1
1 3 1 2
1 3 1 3
1 3 2 2
1 3 2 3
1 3 3 3
2 1 1 1
2 1 1 2
2 1 1 3
2 1 2 2
2 1 2 3
2 1 3 3
2 2 1 1
2 2 1 2
2 2 1 3
2 2 2 2
2 2 2 3
2 2 3 3
2 3 1 1
2 3 1 2
2 3 1 3
2 3 2 2
2 3 2 3
2 3 3 3
3 1 1 1
3...

output:

-1
1
1
-1
-1
-1
-1
2
1
-1
-1
-1
-1
2
2
-1
-1
-1
-1
1
1
-1
1
-1
-1
1
1
-1
2
-1
-1
2
1
-1
3
-1
-1
1
1
-1
1
-1
-1
1
1
-1
2
-1
-1
1
1
-1
2
-1

result:

ok 54 lines

Test #3:

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

input:

54
10 10 10 10
10 10 10 11
10 10 10 12
10 10 11 11
10 10 11 12
10 10 12 12
10 11 10 10
10 11 10 11
10 11 10 12
10 11 11 11
10 11 11 12
10 11 12 12
10 12 10 10
10 12 10 11
10 12 10 12
10 12 11 11
10 12 11 12
10 12 12 12
11 10 10 10
11 10 10 11
11 10 10 12
11 10 11 11
11 10 11 12
11 10 12 12
11 11 10 ...

output:

-1
10
5
-1
-1
-1
-1
11
5
-1
-1
-1
-1
11
5
-1
-1
-1
-1
10
4
-1
10
-1
-1
10
5
-1
11
-1
-1
11
5
-1
12
-1
-1
9
4
-1
10
-1
-1
10
5
-1
11
-1
-1
10
5
-1
11
-1

result:

ok 54 lines

Test #4:

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

input:

54
4 4 4 4
4 4 4 5
4 4 4 6
4 4 5 5
4 4 5 6
4 4 6 6
4 5 4 4
4 5 4 5
4 5 4 6
4 5 5 5
4 5 5 6
4 5 6 6
4 6 4 4
4 6 4 5
4 6 4 6
4 6 5 5
4 6 5 6
4 6 6 6
5 4 4 4
5 4 4 5
5 4 4 6
5 4 5 5
5 4 5 6
5 4 6 6
5 5 4 4
5 5 4 5
5 5 4 6
5 5 5 5
5 5 5 6
5 5 6 6
5 6 4 4
5 6 4 5
5 6 4 6
5 6 5 5
5 6 5 6
5 6 6 6
6 4 4 4
6...

output:

-1
4
2
-1
-1
-1
-1
5
2
-1
-1
-1
-1
5
3
-1
-1
-1
-1
4
2
-1
4
-1
-1
4
2
-1
5
-1
-1
5
3
-1
6
-1
-1
3
2
-1
4
-1
-1
4
2
-1
5
-1
-1
4
2
-1
5
-1

result:

ok 54 lines

Test #5:

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

input:

54
7 7 7 7
7 7 7 8
7 7 7 9
7 7 8 8
7 7 8 9
7 7 9 9
7 8 7 7
7 8 7 8
7 8 7 9
7 8 8 8
7 8 8 9
7 8 9 9
7 9 7 7
7 9 7 8
7 9 7 9
7 9 8 8
7 9 8 9
7 9 9 9
8 7 7 7
8 7 7 8
8 7 7 9
8 7 8 8
8 7 8 9
8 7 9 9
8 8 7 7
8 8 7 8
8 8 7 9
8 8 8 8
8 8 8 9
8 8 9 9
8 9 7 7
8 9 7 8
8 9 7 9
8 9 8 8
8 9 8 9
8 9 9 9
9 7 7 7
9...

output:

-1
7
3
-1
-1
-1
-1
8
4
-1
-1
-1
-1
8
4
-1
-1
-1
-1
7
3
-1
7
-1
-1
7
4
-1
8
-1
-1
8
4
-1
9
-1
-1
6
3
-1
7
-1
-1
7
3
-1
8
-1
-1
7
3
-1
8
-1

result:

ok 54 lines

Test #6:

score: 0
Accepted
time: 31ms
memory: 3572kb

input:

100
87279562 988175500 990523511 990564829
87279562 988175500 990523511 990564829
87279562 988175500 990523511 990564829
87279562 988175500 990523511 990564829
87279562 988175500 990523511 990564829
87279562 988175500 990523511 990564829
87279562 988175500 990523511 990564829
87279562 988175500 9905...

output:

60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
60211
...

result:

ok 100 lines

Test #7:

score: 0
Accepted
time: 43ms
memory: 3544kb

input:

100
87839551 946797927 997674962 997719821
84639029 937626238 967565279 967605464
88780980 927643809 977431321 977456494
87414331 969173593 998994970 999022111
86792036 944654580 998921274 998952614
83742396 964865875 998076549 998106097
84763083 979606748 990526157 990570521
82405631 918491597 9978...

output:

54855
59992
94669
91739
78901
85381
56499
61590
44734
99317
54855
59992
94669
91739
78901
85381
56499
61590
44734
99317
54855
59992
94669
91739
78901
85381
56499
61590
44734
99317
54855
59992
94669
91739
78901
85381
56499
61590
44734
99317
54855
59992
94669
91739
78901
85381
56499
61590
44734
99317
...

result:

ok 100 lines

Test #8:

score: -100
Time Limit Exceeded

input:

100
1000000000 500000000 500000000 500000001
1000000000 333333333 333333333 333333334
1000000000 250000000 250000000 250000001
1000000000 200000000 200000000 200000001
1000000000 166666666 166666666 166666667
1000000000 142857142 142857142 142857143
1000000000 125000000 125000000 125000001
100000000...

output:


result: