101712024-03-28 23:08:43111Házszámokcpp17Wrong answer 25/1003ms5208 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),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;
		}
	}
	if(h==1e17)exit(1);
	cout<<h-1<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1704 KiB
2Accepted3ms1860 KiB
3Accepted3ms2208 KiB
subtask20/25
4Accepted3ms2432 KiB
5Accepted3ms2528 KiB
6Accepted3ms2740 KiB
7Wrong answer3ms2932 KiB
8Accepted3ms3024 KiB
9Accepted3ms3148 KiB
10Accepted3ms3220 KiB
11Accepted3ms3220 KiB
12Accepted3ms3348 KiB
13Accepted3ms3712 KiB
14Accepted3ms3780 KiB
15Wrong answer3ms3792 KiB
16Accepted3ms3768 KiB
17Accepted3ms3900 KiB
18Accepted3ms4112 KiB
19Wrong answer3ms4208 KiB
subtask310/10
20Accepted3ms4208 KiB
21Accepted3ms4300 KiB
22Accepted3ms4300 KiB
23Accepted3ms4400 KiB
24Accepted3ms4432 KiB
subtask415/15
25Accepted3ms4408 KiB
26Accepted3ms4412 KiB
27Accepted3ms4404 KiB
28Accepted3ms4404 KiB
29Accepted3ms4508 KiB
30Accepted3ms4508 KiB
31Accepted3ms4512 KiB
32Accepted3ms4404 KiB
33Accepted3ms4532 KiB
subtask50/20
34Accepted3ms4620 KiB
35Accepted3ms4992 KiB
36Wrong answer3ms4768 KiB
37Wrong answer3ms4864 KiB
38Accepted3ms4864 KiB
39Accepted3ms4868 KiB
40Accepted3ms4836 KiB
41Accepted3ms4924 KiB
42Accepted3ms4840 KiB
subtask60/30
43Accepted3ms5092 KiB
44Accepted3ms4844 KiB
45Accepted3ms4848 KiB
46Accepted3ms4940 KiB
47Accepted3ms4936 KiB
48Wrong answer3ms4940 KiB
49Accepted3ms5084 KiB
50Accepted3ms5016 KiB
51Accepted3ms5108 KiB
52Wrong answer3ms5108 KiB
53Accepted3ms5104 KiB
54Accepted3ms5208 KiB
55Accepted3ms5112 KiB
56Accepted3ms4916 KiB
57Accepted3ms5012 KiB
58Accepted3ms4916 KiB
59Accepted3ms4920 KiB
60Wrong answer3ms5024 KiB