QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694291#9129. Quotient Sumicpc_zhzx034#TL 688ms6892kbC++141.5kb2024-10-31 17:39:432024-10-31 17:39:44

Judging History

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

  • [2024-10-31 17:39:44]
  • 评测
  • 测评结果:TL
  • 用时:688ms
  • 内存:6892kb
  • [2024-10-31 17:39:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pr;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
// #define mid ((l+r)>>1)
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
	ll x=0, f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
	return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
	ll ans=1, base=a;
	while(b){
		if(b&1) ans=ans*base%mod;
		base=base*base%mod; b>>=1;
	}
	return ans;
}
void init(){ }
ll n,a[200005],dp[200005];
ll DP(ll x){
	// cout<<"solving "<<x<<endl;
	if(x == 1) return 0;
	if(~dp[x]) return dp[x];
	dp[x] = 1e18;

	ll pt = x-1;
	while(pt >= 1){
		ll val = a[x] / a[pt];
		ll l=1, r=pt, ans=pt;
		while(l<=r){
			ll mid=(l+r)>>1;
			assert(a[mid]);
			if(a[x]/a[mid] == val){
				ans=mid;
				r=mid-1;
			}else l=mid+1;
		}
		dp[x] = min(dp[x], DP(ans) + val);
		// cout<<"trans "<<x<<" to "<<ans<<endl;
		pt = ans - 1;
	}
	return dp[x];
}
void procedure(){
	memset(dp, -1, sizeof(dp));
	n=read();
	for(ll i=1;i<=n;i++) a[i]=read();
	sort(a+1, a+n+1);
	printf("%lld\n", DP(n));
}
int main(){
	#ifdef LOCAL
		assert(freopen("input.txt","r",stdin));
		assert(freopen("output.txt","w",stdout));
	#endif
	ll T=1;
	init();
	while(T--) procedure();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 3 6

output:

3

result:

ok "3"

Test #2:

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

input:

2
15 4

output:

3

result:

ok "3"

Test #3:

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

input:

9
284791808 107902 13660981249408 4622332661 13405199 24590921 361 244448137 16077087227955422

output:

4580

result:

ok "4580"

Test #4:

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

input:

9
12 9 5 17 2 6 7 1 15

output:

6

result:

ok "6"

Test #5:

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

input:

10
19 13 18 11 20 16 6 8 17 3

output:

4

result:

ok "4"

Test #6:

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

input:

8
5 7 11 16 2 15 1 20

output:

7

result:

ok "7"

Test #7:

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

input:

10
13 2 19 11 15 9 16 5 12 1

output:

7

result:

ok "7"

Test #8:

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

input:

8
9 1 14 11 3 12 8 20

output:

7

result:

ok "7"

Test #9:

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

input:

4
4 6 20 3

output:

5

result:

ok "5"

Test #10:

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

input:

382
1495 1297 1197 976 1335 486 1850 992 1483 1269 1898 1593 237 1342 711 957 1992 1401 1413 206 917 1831 1444 698 1291 1987 231 1559 1119 1822 1790 471 736 496 1157 1886 1974 699 1702 321 325 758 683 1826 1051 95 632 456 1224 1590 1394 1854 1226 1963 1926 1819 989 34 980 371 535 807 1541 144 433 12...

output:

11

result:

ok "11"

Test #11:

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

input:

317
1565 1374 387 1215 766 1670 862 673 1391 70 727 152 182 26 1111 1430 64 1318 349 994 780 1762 1993 552 715 1943 967 972 1039 646 617 1822 373 486 1863 1179 1840 1781 1963 220 773 671 126 613 719 1660 334 1851 65 707 1862 490 1466 1590 1717 1723 656 1526 1138 31 1976 1823 1335 1719 397 612 593 13...

output:

8

result:

ok "8"

Test #12:

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

input:

100
1070 947 7 1735 476 1172 995 2000 536 15 1499 656 1810 1435 639 1647 61 630 4 754 1594 442 1644 1743 5 629 1879 1707 1174 1984 1526 1829 1449 783 1483 1734 1032 494 537 1872 1117 1316 1069 780 520 689 31 1970 1653 1071 251 360 1063 988 1154 638 547 525 264 495 273 436 967 633 462 1863 164 402 18...

output:

12

result:

ok "12"

Test #13:

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

input:

495
368 27 1415 966 351 1575 449 1982 15 1207 1806 1483 1304 1488 750 1751 1047 314 1833 1365 1281 589 1062 419 1430 345 41 230 1248 11 338 1139 1146 1892 281 1994 950 26 1247 817 1250 131 1954 631 1020 1705 382 220 172 1434 1841 1866 849 793 1236 53 1275 1366 1038 1889 615 1652 218 1862 84 377 76 1...

output:

19

result:

ok "19"

Test #14:

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

input:

452
1711 258 865 1330 1923 4 1656 652 1660 1768 603 1841 646 1810 1235 200 503 1083 418 511 1803 886 54 213 1914 734 1531 1941 272 1686 1873 1831 1367 1746 141 404 1538 989 768 1830 1684 426 527 1872 1105 1655 540 1444 331 767 1896 49 1141 921 772 307 614 764 848 1997 1406 339 63 828 416 1891 1925 6...

output:

11

result:

ok "11"

Test #15:

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

input:

61
320 456 426 201 1105 1894 570 661 1307 618 956 1185 1241 6 574 1236 604 462 1900 1488 697 1688 1085 775 635 747 1252 1721 431 192 768 1798 1712 686 1496 932 1309 1431 904 1467 1863 804 856 1682 1159 78 1276 211 942 848 270 225 117 302 1418 1951 534 1345 591 110 1967

output:

19

result:

ok "19"

Test #16:

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

input:

6007
926195740081456592 954460021832145143 601395744686943902 21575530228356921 463431657670752021 711276919720293649 916086948281828983 942717046975828490 627872019769751663 375556646744053894 531095909932455304 993855300776486066 208335586285140634 319193845177757965 985795314563730251 10507706789...

output:

12

result:

ok "12"

Test #17:

score: 0
Accepted
time: 688ms
memory: 6104kb

input:

8261
284791808 107902 13660981249408 4622332661 13405199 24590921 361 244448137 16077087227955422 29020 2999 243823 11405 3084850839644 51410 1293 598217528 6419212814 19670 42431 16305842936592 588083868939790 35416223344083524 1670928183457 462015428 19431 7573789315 819 4594126473685 8554104 1422...

output:

63

result:

ok "63"

Test #18:

score: 0
Accepted
time: 2ms
memory: 5372kb

input:

6015
358871240359366151 224257618022883235 172819476860570817 75125953034362365 824984506523526062 988848382335902687 898522089822105149 755567463105677238 970409760639198928 430709898290812041 779827111538256956 857511190324448260 329465323773300663 685019732014997951 197724427289098867 15126091335...

output:

14

result:

ok "14"

Test #19:

score: 0
Accepted
time: 57ms
memory: 5348kb

input:

2319
7 769 14566 213732121851657504 3031249 117432 1853 43404611161 2137819942 2525662612281 575 628859144901512192 82402637244386 570993657677445760 244 540730562 190876 146904 11282 2881663495750947 36247 410727237 100465424998099 48557284 334485561776644672 1611191 191632019669065056 203 2122865 ...

output:

64

result:

ok "64"

Test #20:

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

input:

3647
191274254202747070 816451465136605666 632954453162088720 316484101993458936 400530481203520131 36361261508615425 107377728836074713 479766874026239333 132490733793819615 701342570200191348 393529093120808255 997930221798392349 37262148109322604 236346409115411 445572155956552286 578658600443172...

output:

15

result:

ok "15"

Test #21:

score: 0
Accepted
time: 63ms
memory: 5496kb

input:

2459
1418053410414 637622553455 1470 1931006024625 27526276968 4967139053 521674647989055 186443981371189 39480756299336 95680188183 2727948481 557901603 11423 10709859272749 242760849 307283093727562688 42213 3181 518822290138407936 1532145441957570 40684208181105 254735022780282 56 58 5905 166 193...

output:

63

result:

ok "63"

Test #22:

score: 0
Accepted
time: 10ms
memory: 6296kb

input:

113844
462209310844307827 895186606000026911 536883699910050004 923768182795407203 116843726498620270 837342622857072639 5401336272754811 956408591677017253 644988425043116019 643246228819184945 544277427880226394 694401128212891523 352892254813391858 739821579965916396 991683818573040504 7744776087...

output:

16

result:

ok "16"

Test #23:

score: -100
Time Limit Exceeded

input:

194435
2691485 412893522790905728 14698764318 223230348450 79466646146 106916997248562 668789825 15651263346034818 6602164367069652 7736843382176793 398591166927295 21282612274422 12609786010 463 73237470025259248 1756698204 17854370570384 364588 13045 1165416117509 22557532638431 28889662774652 649...

output:


result: