101692024-03-28 23:02:09111Házszámokcpp17Wrong answer 25/1003ms5424 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int K;
	cin>>K;
	vector<int>v(K);
	for(int i=0;i<K;i++){
		cin>>v[i];
	}
	v[0]++;
	auto calc=[&](int n,int i)->int{
		int x=0;
		if(i>0){
			for(int p=1;p<=n;p*=K){
				x+=n/(p*K)*p;
				x+=min(max(n%(p*K)-p*i,0ll),p);
			}
		}
		else{
			for(int p=1;p<=n;p*=K){
				x+=max((n/(p*K)-1)*p,0ll);
			}
		}
		return x;
	};
	int l=1,h=1e17;
	while(l<h){
		int m=(l+h)/2;
		int ok=1;
		for(int i=0;i<K;i++){
			ok&=calc(m+1,i)<=v[i];
		}
		if(ok){
			l=m+1;
		}
		else{
			h=m;
		}
	}
	cout<<h-1<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2060 KiB
3Accepted3ms2268 KiB
subtask20/25
4Accepted3ms2324 KiB
5Wrong answer3ms2444 KiB
6Wrong answer3ms2524 KiB
7Wrong answer3ms2652 KiB
8Accepted3ms2888 KiB
9Accepted3ms2816 KiB
10Wrong answer3ms2808 KiB
11Accepted3ms2812 KiB
12Accepted3ms2808 KiB
13Accepted3ms3044 KiB
14Accepted3ms3040 KiB
15Wrong answer3ms3040 KiB
16Accepted3ms3168 KiB
17Accepted3ms3380 KiB
18Accepted3ms3492 KiB
19Wrong answer3ms3564 KiB
subtask310/10
20Accepted3ms3696 KiB
21Accepted3ms3800 KiB
22Accepted3ms3708 KiB
23Accepted2ms3708 KiB
24Accepted3ms3688 KiB
subtask415/15
25Accepted3ms3780 KiB
26Accepted3ms3912 KiB
27Accepted3ms4124 KiB
28Accepted3ms4484 KiB
29Accepted3ms4360 KiB
30Accepted3ms4268 KiB
31Accepted3ms4368 KiB
32Accepted3ms4396 KiB
33Accepted3ms4480 KiB
subtask50/20
34Accepted3ms4480 KiB
35Accepted3ms4480 KiB
36Wrong answer3ms4852 KiB
37Wrong answer3ms4652 KiB
38Accepted3ms4624 KiB
39Accepted3ms4820 KiB
40Accepted3ms5036 KiB
41Accepted3ms5116 KiB
42Accepted3ms5116 KiB
subtask60/30
43Wrong answer3ms5116 KiB
44Wrong answer3ms5116 KiB
45Wrong answer3ms5112 KiB
46Accepted3ms5112 KiB
47Accepted3ms5116 KiB
48Wrong answer3ms5216 KiB
49Accepted3ms5120 KiB
50Accepted3ms5128 KiB
51Accepted3ms5272 KiB
52Wrong answer3ms5128 KiB
53Accepted3ms5132 KiB
54Accepted3ms5132 KiB
55Accepted3ms5128 KiB
56Accepted3ms5220 KiB
57Accepted3ms5316 KiB
58Accepted3ms5324 KiB
59Accepted3ms5424 KiB
60Wrong answer3ms5328 KiB