QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#477525 | #9129. Quotient Sum | ucup-team3099# | TL | 425ms | 3824kb | C++20 | 4.1kb | 2024-07-14 04:49:32 | 2024-07-14 04:49:33 |
Judging History
answer
#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
#if 0
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
template<class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>, __gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update>;
#endif
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <random>
#include <chrono>
#include <cassert>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define each(a,x) for (auto& a: x)
#define tcT template<class T
#define tcTU tcT, class U
#define tcTUU tcT, class ...U
template<class T> using V = vector<T>;
template<class T, size_t SZ> using AR = array<T,SZ>;
typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(vector<bool> v) { str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]); res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; F0R(i,SZ) res += char('0'+b[i]); return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) {if (!fst) res += ", "; fst = 0; res += ts(x);} res += "}"; return res;}
template<class A, class B> str ts(pair<A,B> p) {return "("+ts(p.first)+", "+ts(p.second)+")"; }
template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) { pr(h); pr(t...); }
void ps() { pr("\n"); }
template<class H, class... T> void ps(const H& h, const T&... t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {cerr << ts(h); if (sizeof...(t)) cerr << ", "; DBG(t...); }
tcTU> void re(pair<T,U>& p);
tcT> void re(V<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);
tcT> void re(T& x) { cin >> x; }
void re(double& d) { str t; re(t); d = stod(t); }
void re(long double& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }
tcTU> void re(pair<T,U>& p) { re(p.first,p.second); }
tcT> void re(V<T>& x) { each(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { each(a,x) re(a); }
tcT> void rv(int n, V<T>& x) { x.rsz(n); re(x); }
constexpr bool multitest() {return 0;}
void solve();
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int t = 1;
if (multitest()) cin >> t;
for (; t; t--) solve();
}
void solve() {
int n; re(n);
vector<ll> a(n); re(a);
sort(all(a));
vector<ll> cost(n, 1000000000000000000ll);
cost[0] = 0;
int l = 1;
while (l*2 < n) l *= 2;
for (int i = 0; i < n; i++) {
int j = i+1;
int c = 0;
while (j < n && c < 10) {
for (int d = l; d >= 1; d--) if (j+d < n && a[j+d]/a[i] == a[j]/a[i]) j += d;
ctmin(cost[j], cost[i] + a[j]/a[i]);
j++;
c++;
}
}
ps(cost[n-1]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
3 2 3 6
output:
3
result:
ok "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 15 4
output:
3
result:
ok "3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
9 284791808 107902 13660981249408 4622332661 13405199 24590921 361 244448137 16077087227955422
output:
4580
result:
ok "4580"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
9 12 9 5 17 2 6 7 1 15
output:
6
result:
ok "6"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3684kb
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: 3692kb
input:
8 5 7 11 16 2 15 1 20
output:
7
result:
ok "7"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3660kb
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: 3664kb
input:
8 9 1 14 11 3 12 8 20
output:
7
result:
ok "7"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
4 4 6 20 3
output:
5
result:
ok "5"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3824kb
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: 2ms
memory: 3632kb
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: 3792kb
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: 3ms
memory: 3632kb
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: 3788kb
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: 0ms
memory: 3784kb
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: 425ms
memory: 3724kb
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: -100
Time Limit Exceeded
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...