101682024-03-28 23:01:30111Házszámokcpp17Wrong answer 25/1003ms5392 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+=(n/(p*K)-1)*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
1Accepted3ms1828 KiB
2Accepted3ms2052 KiB
3Accepted3ms2264 KiB
subtask20/25
4Accepted2ms2348 KiB
5Wrong answer3ms2316 KiB
6Wrong answer3ms2596 KiB
7Wrong answer3ms2532 KiB
8Accepted3ms2772 KiB
9Accepted3ms2868 KiB
10Wrong answer3ms2964 KiB
11Accepted3ms3164 KiB
12Accepted3ms3376 KiB
13Accepted3ms3728 KiB
14Accepted3ms3680 KiB
15Wrong answer3ms3772 KiB
16Accepted3ms3776 KiB
17Accepted3ms3860 KiB
18Accepted3ms3896 KiB
19Wrong answer3ms3908 KiB
subtask310/10
20Accepted3ms4052 KiB
21Accepted3ms3944 KiB
22Accepted3ms4044 KiB
23Accepted3ms4040 KiB
24Accepted3ms3940 KiB
subtask415/15
25Accepted3ms4076 KiB
26Accepted3ms4204 KiB
27Accepted3ms4308 KiB
28Accepted3ms4300 KiB
29Accepted3ms4300 KiB
30Accepted3ms4412 KiB
31Accepted3ms4652 KiB
32Accepted3ms4856 KiB
33Accepted3ms4940 KiB
subtask50/20
34Accepted3ms5068 KiB
35Accepted3ms5276 KiB
36Wrong answer3ms5384 KiB
37Wrong answer3ms5392 KiB
38Accepted3ms5068 KiB
39Accepted3ms5072 KiB
40Accepted3ms5072 KiB
41Accepted3ms5072 KiB
42Accepted3ms5220 KiB
subtask60/30
43Wrong answer3ms5180 KiB
44Wrong answer3ms5076 KiB
45Wrong answer3ms5076 KiB
46Accepted3ms5180 KiB
47Accepted3ms5080 KiB
48Wrong answer3ms5176 KiB
49Accepted3ms5176 KiB
50Accepted3ms5284 KiB
51Accepted3ms5284 KiB
52Wrong answer3ms5084 KiB
53Accepted3ms5076 KiB
54Accepted3ms5188 KiB
55Accepted3ms5080 KiB
56Accepted3ms5180 KiB
57Accepted3ms5080 KiB
58Accepted3ms5076 KiB
59Accepted3ms5084 KiB
60Wrong answer3ms5176 KiB