QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#823337#9061. Streets BehindLaVuna47AC ✓52ms3708kbC++172.0kb2024-12-20 22:09:472024-12-20 22:09:48

Judging History

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

  • [2024-12-20 22:09:48]
  • 评测
  • 测评结果:AC
  • 用时:52ms
  • 内存:3708kb
  • [2024-12-20 22:09:47]
  • 提交

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif


int solve()
{
	ll n,k,a,b;
	if(!(cin>>n>>k>>a>>b))return 1;
	//cout<<n<<" " << k<<" " << a <<" " << b <<endl;
	if(b*n < a*(n+1))
	{
		cout<<"-1\n";
		return 0;
	}
	ll y=(n*b-a*n)/a;
	ll res=0;
	//cout<<"y="<<y<<endl;
	for(; k > 0;)
	{
		ll x = (a*n + y*a + a - n*b + (b*y - y*a-1)) / (b*y - y*a);
		if(k-y*x < 0)
		{
			res += (k+y-1)/(y);
			break;
		}
		else
		{
			if(x==0)
			{
				++res;
				break;
			}
			res += x;
			k -= y*x;
			n += y*x;
			y=max(y+1,(n*b-a*n)/a);
			//cout<<"dres="<<x<<endl;
		}
		//cout<<"y="<<y<<endl;
	}
	cout<<res<<'\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
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

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: 3564kb

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: 3704kb

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: 1ms
memory: 3620kb

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: 3648kb

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: 52ms
memory: 3548kb

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: 44ms
memory: 3568kb

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: 0
Accepted
time: 0ms
memory: 3708kb

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:

250000000
111111111
62500000
40000000
27777778
20408164
15625000
12345679
10000000
8264463
6944445
5917160
5102041
4444445
3906250
3460208
3086420
2770084
2500000
2267574
2066116
1890360
1736112
1600000
1479290
1371743
1275511
1189061
1111112
1040583
976563
918274
865052
816327
771605
730461
692521
...

result:

ok 100 lines

Test #9:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

100
210439921 104840758 477034045 560474791
576623637 734211729 277967202 761499243
79444535 227451617 857575422 973619369
900413104 105285201 742065157 917522487
262210823 552004848 461401346 599095673
830210840 675602119 900533480 955055695
905324791 368383419 536634011 583047720
12365097 98944249...

output:

3
1
11
1
5
11
5
10
2
1
2
1
1
1
2
6
2
37
1
19
3
1
6
1
2
3
49
25
2
1
53
9
1
2
1
2
1
12
1
1
3
5
1
1377
90
2
1
1
1
1
1
1
1
38
39
3
2
1
5
1
1
1
1
21
53
4
3
8
88
1
4
1
2
1
1
5
1
2
47
5
12
1
1
1
5
3
2
1
5
1
5
3
1
1
4
5
1
5
17
3

result:

ok 100 lines

Test #10:

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

input:

100
541812942 462487046 819074082 940151952
394395730 308394903 251654730 330814001
466497307 433783361 984714678 998214987
479687127 617591919 232660684 520597939
919956159 975882908 646289878 715399962
505013791 263051626 850037272 946292249
969438977 536640271 588980505 779116890
705805934 245864...

output:

5
3
49
2
8
4
2
1
1
1
10
2
3
31
5
2
9
5
3
1
1
1
2
3
2
5
2
1
12
6
8
5
1
3
18
1
2
2
28
9
2
1
2
1
67
5
1
1
19
1
32
1
44
2
6
1
2
32
5
34
4
2
2
2
3
1
2
5
1
13
2
1
1
4
8
218
1
17
1
7
127
1
2
2
7
9
2
3
1
1
47
22
1
1
8
921
7
4
1
14

result:

ok 100 lines

Test #11:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

100
747567603 756470732 83330269 682428004
521037911 788595220 805415630 999524587
239057062 650798777 605109502 656944695
510463978 639177267 407377769 528942093
260537680 626482609 348379280 663389490
214197053 219072298 36311369 718722538
793343886 238462358 854191211 890672051
596470776 66709244...

output:

1
5
16
4
2
1
7
26
11
6
1
5
1
31
2
1
2
1
1
6
36
5
8
3
1
1
7
2
1
1
15
2
4
1049
1
2
1
5
1
1
1
2
1
17
2
10
5
4
35
15
3
2
1
17
3
3
2
68
11
23
12
2
1
2
4
1
1
1302
35
1
2
1
1
14
1
19
3
7
5
2
1
2
304
2
6
1
4
1
1
2
358
23
1
8
6
2
6
9
7
8

result:

ok 100 lines

Test #12:

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

input:

100
1141577 7354376 824611320 943725707
361075111 626743026 842968362 857268096
785338626 172646635 793031038 909382495
211839121 612243881 928795451 988931451
923565456 649510512 611341203 822965423
139083314 294548332 238141215 900861356
982696269 723695852 751696038 760047504
282142007 335431497 ...

output:

15
60
2
22
2
1
50
1
48
35
1
2
20
1
21
1
1
3
20
1
3
3
1
11
2
1
16
2
5
1
1
3
1713
7
3
11
2
1
1
2
1
4
1
2
538
1
26
5
13
8
1
2
14
55
3
24
5
2
19
5
6
8
9
2
1
1
2196
5
4
3
1
2
1
1
1
2
9
7
9
1
1
15
15
172
1
5
1
1
2
30
1
9
7
1
1
3
4
8
2
3

result:

ok 100 lines

Test #13:

score: 0
Accepted
time: 1ms
memory: 3576kb

input:

100
49 6 79 97
15 41 76 83
94 58 67 96
87 46 88 95
80 16 43 89
14 70 30 40
87 33 34 74
100 2 77 77
76 2 52 85
50 14 99 100
42 23 6 17
7 85 1 80
12 90 83 89
55 81 54 87
59 14 81 87
90 49 17 93
67 40 32 53
9 2 75 94
17 23 33 74
82 43 80 93
24 51 22 34
11 66 92 93
33 30 80 90
5 59 74 100
68 49 2 78
77 ...

output:

1
20
2
6
1
7
1
-1
1
-1
1
1
-1
2
4
1
1
1
2
3
3
-1
6
10
1
4
2
-1
1
1
13
1
2
8
2
1
2
1
1
3
1
1
1
1
1
1
1
1
1
2
1
1
1
1
4
2
1
-1
1
1
13
1
24
4
1
-1
-1
3
28
1
-1
2
3
7
2
1
1
15
1
1
1
2
-1
49
4
39
21
1
1
1
1
2
2
2
3
1
2
1
11
6

result:

ok 100 lines

Test #14:

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

input:

100
136 898 739 922
527 186 793 838
231 115 530 885
162 672 108 972
170 576 619 942
690 890 621 896
577 819 182 193
141 111 269 678
819 390 679 826
872 790 461 932
30 191 806 825
490 668 197 824
15 987 412 460
446 130 988 988
449 668 816 988
414 105 185 701
355 814 43 53
164 423 353 759
757 415 450 ...

output:

10
6
1
1
4
3
16
1
2
1
-1
1
42
-1
5
1
6
2
1
10
11
-1
1
16
1
4
19
1
2
5
1
3
20
3
1
1
2
6
1
16
3
2
58
1
3
5
22
2
1
1
160
1
1
24
15
5
1
2
1
2
5
2
13
45
3
2
1
143
2
13
3
2
34
1
127
2
2
45
1
1
5
3
8
1
2
2
7
2
13
7
29
16
21
-1
2
2
6
5
1
2

result:

ok 100 lines

Test #15:

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

input:

100
124820 870265 422519 877401
753014 7260 377336 736472
167709 60601 600631 967620
646012 248079 29650 887849
955592 200340 969954 993803
110282 337942 311614 638790
967263 880085 476026 505039
27359 596800 114032 635913
432052 796950 752570 758974
508307 426755 809317 949623
525256 523968 530727 ...

output:

3
1
1
1
8
2
11
2
124
4
2
5
167
9
14
6
14
1
1
3
1
11
1
2
4
4
3
11
5
10
188
3
28
5
5
13
2
3
13
8
2
2
1
4
3
212
2
42
2
9
13
5
5
3
1
1
3
26
3
5
1
1
10
2
1489
2
1
1
2
2
4
1
4
5
4
3
1
2
8
3
1
13
21
2
19
210
7
9
6
1
5
5
24
15
5
39
31
4
1
1

result:

ok 100 lines