101702024-03-28 23:06:18111Házszámokcpp17Wrong answer 25/1003ms5428 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);
				if(n>=p*K){
					x+=min(max(n%(p*K)-p*i,0ll),p);
				}
			}
		}
		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
1Accepted3ms1832 KiB
2Accepted3ms2168 KiB
3Accepted3ms2436 KiB
subtask20/25
4Accepted3ms2208 KiB
5Accepted3ms2352 KiB
6Accepted3ms2560 KiB
7Wrong answer3ms2772 KiB
8Accepted3ms2856 KiB
9Accepted3ms2852 KiB
10Accepted3ms3140 KiB
11Accepted3ms3200 KiB
12Accepted3ms3340 KiB
13Accepted3ms3440 KiB
14Accepted3ms3436 KiB
15Wrong answer3ms3500 KiB
16Accepted3ms3712 KiB
17Accepted3ms3912 KiB
18Accepted3ms3916 KiB
19Wrong answer3ms3896 KiB
subtask310/10
20Accepted3ms3904 KiB
21Accepted3ms4000 KiB
22Accepted3ms3992 KiB
23Accepted3ms3992 KiB
24Accepted3ms4092 KiB
subtask415/15
25Accepted3ms4128 KiB
26Accepted3ms4216 KiB
27Accepted3ms4208 KiB
28Accepted3ms4212 KiB
29Accepted3ms4340 KiB
30Accepted3ms4424 KiB
31Accepted3ms4428 KiB
32Accepted3ms4520 KiB
33Accepted3ms4432 KiB
subtask50/20
34Accepted3ms4652 KiB
35Accepted3ms4636 KiB
36Wrong answer3ms4768 KiB
37Wrong answer3ms4852 KiB
38Accepted3ms4856 KiB
39Accepted3ms4856 KiB
40Accepted3ms4860 KiB
41Accepted3ms4856 KiB
42Accepted3ms4980 KiB
subtask60/30
43Accepted3ms5068 KiB
44Accepted3ms5200 KiB
45Accepted3ms5276 KiB
46Accepted3ms5428 KiB
47Accepted3ms5292 KiB
48Wrong answer3ms5392 KiB
49Accepted3ms5284 KiB
50Accepted3ms5176 KiB
51Accepted3ms5332 KiB
52Wrong answer3ms5292 KiB
53Accepted3ms5176 KiB
54Accepted3ms5184 KiB
55Accepted3ms5192 KiB
56Accepted3ms5184 KiB
57Accepted3ms5192 KiB
58Accepted3ms5188 KiB
59Accepted3ms5188 KiB
60Wrong answer3ms5292 KiB