Task: | Ladders |
Sender: | aalto2024g_007 |
Submission time: | 2024-10-09 17:01:12 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.09 s | details |
#2 | ACCEPTED | 0.11 s | details |
#3 | ACCEPTED | 0.09 s | details |
#4 | ACCEPTED | 0.09 s | details |
#5 | ACCEPTED | 0.10 s | details |
#6 | ACCEPTED | 0.09 s | details |
#7 | ACCEPTED | 0.11 s | details |
#8 | ACCEPTED | 0.10 s | details |
#9 | ACCEPTED | 0.09 s | details |
#10 | ACCEPTED | 0.09 s | details |
#11 | ACCEPTED | 0.10 s | details |
#12 | ACCEPTED | 0.09 s | details |
#13 | ACCEPTED | 0.09 s | details |
#14 | ACCEPTED | 0.09 s | details |
#15 | ACCEPTED | 0.10 s | details |
#16 | ACCEPTED | 0.10 s | details |
#17 | ACCEPTED | 0.09 s | details |
#18 | ACCEPTED | 0.09 s | details |
#19 | ACCEPTED | 0.10 s | details |
#20 | ACCEPTED | 0.10 s | details |
#21 | ACCEPTED | 0.09 s | details |
#22 | ACCEPTED | 0.10 s | details |
#23 | ACCEPTED | 0.10 s | details |
#24 | ACCEPTED | 0.09 s | details |
#25 | ACCEPTED | 0.09 s | details |
#26 | ACCEPTED | 0.10 s | details |
#27 | ACCEPTED | 0.10 s | details |
#28 | ACCEPTED | 0.09 s | details |
#29 | ACCEPTED | 0.10 s | details |
#30 | ACCEPTED | 0.11 s | details |
#31 | ACCEPTED | 0.10 s | details |
#32 | ACCEPTED | 0.09 s | details |
#33 | ACCEPTED | 0.09 s | details |
#34 | ACCEPTED | 0.10 s | details |
#35 | ACCEPTED | 0.10 s | details |
#36 | ACCEPTED | 0.10 s | details |
#37 | ACCEPTED | 0.10 s | details |
#38 | ACCEPTED | 0.10 s | details |
#39 | ACCEPTED | 0.10 s | details |
#40 | ACCEPTED | 0.09 s | details |
#41 | ACCEPTED | 0.09 s | details |
#42 | ACCEPTED | 0.10 s | details |
#43 | ACCEPTED | 0.10 s | details |
#44 | ACCEPTED | 0.10 s | details |
#45 | WRONG ANSWER | 0.10 s | details |
#46 | ACCEPTED | 0.09 s | details |
#47 | ACCEPTED | 0.10 s | details |
#48 | ACCEPTED | 0.10 s | details |
#49 | ACCEPTED | 0.10 s | details |
#50 | ACCEPTED | 0.10 s | details |
#51 | ACCEPTED | 0.10 s | details |
#52 | WRONG ANSWER | 0.10 s | details |
#53 | WRONG ANSWER | 0.10 s | details |
#54 | ACCEPTED | 0.10 s | details |
#55 | ACCEPTED | 0.10 s | details |
#56 | ACCEPTED | 0.10 s | details |
#57 | ACCEPTED | 0.10 s | details |
#58 | ACCEPTED | 0.10 s | details |
#59 | ACCEPTED | 0.10 s | details |
#60 | ACCEPTED | 0.10 s | details |
#61 | WRONG ANSWER | 0.10 s | details |
#62 | WRONG ANSWER | 0.82 s | details |
#63 | ACCEPTED | 0.81 s | details |
#64 | ACCEPTED | 0.81 s | details |
#65 | WRONG ANSWER | 0.82 s | details |
#66 | ACCEPTED | 0.67 s | details |
#67 | WRONG ANSWER | 0.81 s | details |
#68 | ACCEPTED | 0.78 s | details |
#69 | ACCEPTED | 0.80 s | details |
#70 | WRONG ANSWER | 0.80 s | details |
#71 | WRONG ANSWER | 0.80 s | details |
Code
#ifdef ONPC #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #define char unsigned char #define rep(i, a, b) for(int i=a; i< (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define eb emplace_back #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define LSOne(S) ((S) & -(S)) using namespace std; // mt19937 rnd(239); mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> int sgn(T x) { return (T(0) < x) - (x < T(0)); } typedef long double T; typedef complex<T> pt; #define X real() #define Y imag() template<class T> istream& operator>> (istream& is, complex<T>& p) { T value; is >> value; p.real(value); is >> value; p.imag(value); return is; } typedef long long ll; typedef long double ld; using pi = pair<ll, ll>; using vi = vector<ll>; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; int popcnt(int x) { return __builtin_popcount(x); } int popcnt(ll x) { return __builtin_popcountll(x); } #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define LB(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define UB(c, x) distance((c).begin(), upper_bound(all(c), (x))) void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef DEBUG #define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl; #else #define dbg(x...) #endif template<typename S, typename T = S> void chmin(S &s, T t) {s = s < t ? s : t;} template<typename S, typename T = S> void chmax(S &s, T t) {s = s > t ? s : t;} const int INF = 1e9; // 10^9 = 1B is < 2^31-1 const ll LLINF = 4e18; // 4*10^18 is < 2^63-1 const double EPS = 1e-9; const ll MOD = 1e9+7; const int N1=1e5+10; ll dp[N1]; std::map<int, vector<int>> pos; const int N = 10000000; vector<int> lp(N+1); vector<int> pr; set<ll> divs(ll nm) { std::set<ll> res; res.insert(1); for (ll i = 2; i*i <= nm; i++) { if(nm%i==0) { res.insert(i); if(i*i!=nm) { res.insert(nm/i); } } } res.insert(nm); return res; } int solve() { int n; std::cin >> n; vector<ll> v(n+1); for (ll i = 1; i <= n; i++) { std::cin >> v[i]; pos[v[i]].pb(i); } for (ll i = 1; i <= n; i++) { dp[i]=INF; } dp[1]=0; for (ll i = 2; i <= n; i++) { //std::cout << i << ", " << v[i] << ": " << endl; for(auto &d:divs(v[i])) { //std::cout << d << std::endl; for(auto &w:pos[d]) { if(w>=i) continue; dp[i]=min(dp[i], dp[w]+1); } } //std::cout << std::endl; chmin(dp[i], dp[i-1]+1); } std::cout << dp[n] << std::endl; return 0; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int TET = 1; for (int i=2; i <= N; ++i) { if (lp[i] == 0) { lp[i] = i; pr.push_back(i); } for (int j = 0; i * pr[j] <= N; ++j) { lp[i * pr[j]] = pr[j]; if (pr[j] == lp[i]) { break; } } } //cin >> TET; for (int i = 1; i <= TET; i++) { #ifdef ONPC cout << "TEST CASE#" << i << endl; #endif if (solve()) { break; } #ifdef ONPC cout << "__________________________" << endl; #endif } #ifdef ONPC cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; #endif }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 1 |
correct output |
---|
0 |
user output |
---|
0 |
Test 2
Verdict: ACCEPTED
input |
---|
2 2 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 3
Verdict: ACCEPTED
input |
---|
2 1 2 |
correct output |
---|
1 |
user output |
---|
1 |
Test 4
Verdict: ACCEPTED
input |
---|
2 2 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 5
Verdict: ACCEPTED
input |
---|
3 2 3 1 |
correct output |
---|
2 |
user output |
---|
2 |
Test 6
Verdict: ACCEPTED
input |
---|
3 1 2 3 |
correct output |
---|
1 |
user output |
---|
1 |
Test 7
Verdict: ACCEPTED
input |
---|
3 3 2 1 |
correct output |
---|
2 |
user output |
---|
2 |
Test 8
Verdict: ACCEPTED
input |
---|
4 3 2 1 4 |
correct output |
---|
2 |
user output |
---|
2 |
Test 9
Verdict: ACCEPTED
input |
---|
4 4 3 2 1 |
correct output |
---|
3 |
user output |
---|
3 |
Test 10
Verdict: ACCEPTED
input |
---|
4 4 2 1 3 |
correct output |
---|
3 |
user output |
---|
3 |
Test 11
Verdict: ACCEPTED
input |
---|
4 3 2 1 4 |
correct output |
---|
2 |
user output |
---|
2 |
Test 12
Verdict: ACCEPTED
input |
---|
4 1 3 2 4 |
correct output |
---|
1 |
user output |
---|
1 |
Test 13
Verdict: ACCEPTED
input |
---|
5 3 2 4 1 5 |
correct output |
---|
4 |
user output |
---|
4 |
Test 14
Verdict: ACCEPTED
input |
---|
5 1 2 4 3 5 |
correct output |
---|
1 |
user output |
---|
1 |
Test 15
Verdict: ACCEPTED
input |
---|
5 5 3 1 2 4 |
correct output |
---|
3 |
user output |
---|
3 |
Test 16
Verdict: ACCEPTED
input |
---|
5 3 1 4 2 5 |
correct output |
---|
2 |
user output |
---|
2 |
Test 17
Verdict: ACCEPTED
input |
---|
5 1 2 3 4 5 |
correct output |
---|
1 |
user output |
---|
1 |
Test 18
Verdict: ACCEPTED
input |
---|
5 3 1 5 4 2 |
correct output |
---|
2 |
user output |
---|
2 |
Test 19
Verdict: ACCEPTED
input |
---|
5 5 4 3 2 1 |
correct output |
---|
4 |
user output |
---|
4 |
Test 20
Verdict: ACCEPTED
input |
---|
5 5 3 1 4 2 |
correct output |
---|
3 |
user output |
---|
3 |
Test 21
Verdict: ACCEPTED
input |
---|
5 5 4 3 2 1 |
correct output |
---|
4 |
user output |
---|
4 |
Test 22
Verdict: ACCEPTED
input |
---|
5 5 1 4 3 2 |
correct output |
---|
2 |
user output |
---|
2 |
Test 23
Verdict: ACCEPTED
input |
---|
10 4 8 3 1 7 2 5 10 6 9 |
correct output |
---|
3 |
user output |
---|
3 |
Test 24
Verdict: ACCEPTED
input |
---|
10 8 10 3 6 5 1 4 7 2 9 |
correct output |
---|
3 |
user output |
---|
3 |
Test 25
Verdict: ACCEPTED
input |
---|
10 4 1 2 7 5 10 8 6 9 3 |
correct output |
---|
2 |
user output |
---|
2 |
Test 26
Verdict: ACCEPTED
input |
---|
10 10 9 7 2 5 1 3 4 6 8 |
correct output |
---|
4 |
user output |
---|
4 |
Test 27
Verdict: ACCEPTED
input |
---|
10 1 2 3 4 5 6 7 8 9 10 |
correct output |
---|
1 |
user output |
---|
1 |
Test 28
Verdict: ACCEPTED
input |
---|
10 6 7 10 9 5 2 1 3 8 4 |
correct output |
---|
6 |
user output |
---|
6 |
Test 29
Verdict: ACCEPTED
input |
---|
10 10 9 8 7 6 5 4 3 2 1 |
correct output |
---|
9 |
user output |
---|
9 |
Test 30
Verdict: ACCEPTED
input |
---|
10 8 5 3 7 4 1 6 2 10 9 |
correct output |
---|
3 |
user output |
---|
3 |
Test 31
Verdict: ACCEPTED
input |
---|
10 10 9 8 7 6 5 4 3 2 1 |
correct output |
---|
9 |
user output |
---|
9 |
Test 32
Verdict: ACCEPTED
input |
---|
10 10 3 6 8 4 5 1 7 2 9 |
correct output |
---|
2 |
user output |
---|
2 |
Test 33
Verdict: ACCEPTED
input |
---|
100 14 63 92 70 7 59 86 25 60 9 73... |
correct output |
---|
4 |
user output |
---|
4 |
Test 34
Verdict: ACCEPTED
input |
---|
100 92 55 15 16 23 1 24 22 89 71 6... |
correct output |
---|
6 |
user output |
---|
6 |
Test 35
Verdict: ACCEPTED
input |
---|
100 34 58 2 29 82 83 47 100 91 35 ... |
correct output |
---|
3 |
user output |
---|
3 |
Test 36
Verdict: ACCEPTED
input |
---|
100 26 63 34 33 58 41 40 29 22 8 7... |
correct output |
---|
5 |
user output |
---|
5 |
Test 37
Verdict: ACCEPTED
input |
---|
100 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 38
Verdict: ACCEPTED
input |
---|
100 6 85 10 52 5 84 64 92 89 31 60... |
correct output |
---|
1 |
user output |
---|
1 |
Test 39
Verdict: ACCEPTED
input |
---|
100 100 99 98 97 96 95 94 93 92 91... |
correct output |
---|
99 |
user output |
---|
99 |
Test 40
Verdict: ACCEPTED
input |
---|
100 33 75 25 88 30 21 6 11 72 70 3... |
correct output |
---|
5 |
user output |
---|
5 |
Test 41
Verdict: ACCEPTED
input |
---|
100 30 86 34 36 29 12 39 7 65 23 3... |
correct output |
---|
8 |
user output |
---|
8 |
Test 42
Verdict: ACCEPTED
input |
---|
200 14 63 135 70 7 59 198 180 108 ... |
correct output |
---|
6 |
user output |
---|
6 |
Test 43
Verdict: ACCEPTED
input |
---|
200 92 55 151 199 107 153 113 22 1... |
correct output |
---|
5 |
user output |
---|
5 |
Test 44
Verdict: ACCEPTED
input |
---|
200 34 58 2 29 82 162 47 100 91 35... |
correct output |
---|
5 |
user output |
---|
5 |
Test 45
Verdict: WRONG ANSWER
input |
---|
200 148 63 188 153 170 41 180 112 ... |
correct output |
---|
9 |
user output |
---|
10 |
Test 46
Verdict: ACCEPTED
input |
---|
200 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 47
Verdict: ACCEPTED
input |
---|
200 175 162 119 135 5 84 180 92 89... |
correct output |
---|
8 |
user output |
---|
8 |
Test 48
Verdict: ACCEPTED
input |
---|
200 200 199 198 197 196 195 194 19... |
correct output |
---|
199 |
user output |
---|
199 |
Test 49
Verdict: ACCEPTED
input |
---|
200 160 75 25 88 30 21 6 11 72 70 ... |
correct output |
---|
5 |
user output |
---|
5 |
Test 50
Verdict: ACCEPTED
input |
---|
200 30 86 162 36 29 12 145 195 134... |
correct output |
---|
4 |
user output |
---|
4 |
Test 51
Verdict: ACCEPTED
input |
---|
200 47 121 66 36 23 37 113 151 60 ... |
correct output |
---|
6 |
user output |
---|
6 |
Test 52
Verdict: WRONG ANSWER
input |
---|
1000 934 460 976 361 744 297 198 66... |
correct output |
---|
12 |
user output |
---|
13 |
Test 53
Verdict: WRONG ANSWER
input |
---|
1000 999 410 151 405 349 770 809 59... |
correct output |
---|
12 |
user output |
---|
13 |
Test 54
Verdict: ACCEPTED
input |
---|
1000 505 953 714 811 82 503 751 709... |
correct output |
---|
9 |
user output |
---|
9 |
Test 55
Verdict: ACCEPTED
input |
---|
1000 960 63 254 153 973 296 180 300... |
correct output |
---|
6 |
user output |
---|
6 |
Test 56
Verdict: ACCEPTED
input |
---|
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 57
Verdict: ACCEPTED
input |
---|
1000 919 660 119 418 355 220 207 38... |
correct output |
---|
8 |
user output |
---|
8 |
Test 58
Verdict: ACCEPTED
input |
---|
1000 1000 999 998 997 996 995 994 9... |
correct output |
---|
999 |
user output |
---|
999 |
Test 59
Verdict: ACCEPTED
input |
---|
1000 219 802 25 833 912 846 639 806... |
correct output |
---|
5 |
user output |
---|
5 |
Test 60
Verdict: ACCEPTED
input |
---|
1000 821 625 397 588 943 372 469 30... |
correct output |
---|
15 |
user output |
---|
15 |
Test 61
Verdict: WRONG ANSWER
input |
---|
1000 749 481 66 36 256 37 113 712 5... |
correct output |
---|
10 |
user output |
---|
11 |
Test 62
Verdict: WRONG ANSWER
input |
---|
100000 26990 68204 21904 3028 29287 1... |
correct output |
---|
8 |
user output |
---|
9 |
Test 63
Verdict: ACCEPTED
input |
---|
100000 94616 96638 65840 9893 92126 1... |
correct output |
---|
12 |
user output |
---|
12 |
Test 64
Verdict: ACCEPTED
input |
---|
100000 11080 90273 56653 73314 33646 ... |
correct output |
---|
10 |
user output |
---|
10 |
Test 65
Verdict: WRONG ANSWER
input |
---|
100000 27548 48776 71938 59265 12094 ... |
correct output |
---|
11 |
user output |
---|
13 |
Test 66
Verdict: ACCEPTED
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 67
Verdict: WRONG ANSWER
input |
---|
100000 77221 89614 36710 27644 37101 ... |
correct output |
---|
11 |
user output |
---|
17 |
Test 68
Verdict: ACCEPTED
input |
---|
100000 100000 99999 99998 99997 99996... |
correct output |
---|
99999 |
user output |
---|
99999 |
Test 69
Verdict: ACCEPTED
input |
---|
100000 68737 37819 55518 77756 46481 ... |
correct output |
---|
12 |
user output |
---|
12 |
Test 70
Verdict: WRONG ANSWER
input |
---|
100000 39437 53659 60243 20923 38668 ... |
correct output |
---|
11 |
user output |
---|
15 |
Test 71
Verdict: WRONG ANSWER
input |
---|
100000 69631 70212 62831 61461 93551 ... |
correct output |
---|
14 |
user output |
---|
16 |