結果
問題 | No.1262 グラフを作ろう! |
ユーザー | hitonanode |
提出日時 | 2020-10-16 22:23:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 566 ms / 3,000 ms |
コード長 | 2,905 bytes |
コンパイル時間 | 2,188 ms |
コンパイル使用メモリ | 216,016 KB |
実行使用メモリ | 23,252 KB |
最終ジャッジ日時 | 2024-07-20 22:19:44 |
合計ジャッジ時間 | 29,796 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 314 ms
22,696 KB |
testcase_01 | AC | 233 ms
21,668 KB |
testcase_02 | AC | 418 ms
22,692 KB |
testcase_03 | AC | 226 ms
22,948 KB |
testcase_04 | AC | 72 ms
19,364 KB |
testcase_05 | AC | 231 ms
20,972 KB |
testcase_06 | AC | 51 ms
19,312 KB |
testcase_07 | AC | 74 ms
19,612 KB |
testcase_08 | AC | 311 ms
21,208 KB |
testcase_09 | AC | 149 ms
21,856 KB |
testcase_10 | AC | 195 ms
21,032 KB |
testcase_11 | AC | 421 ms
21,280 KB |
testcase_12 | AC | 322 ms
22,432 KB |
testcase_13 | AC | 234 ms
22,820 KB |
testcase_14 | AC | 186 ms
20,644 KB |
testcase_15 | AC | 122 ms
21,416 KB |
testcase_16 | AC | 397 ms
21,412 KB |
testcase_17 | AC | 299 ms
21,520 KB |
testcase_18 | AC | 425 ms
22,564 KB |
testcase_19 | AC | 90 ms
19,488 KB |
testcase_20 | AC | 199 ms
20,344 KB |
testcase_21 | AC | 433 ms
23,040 KB |
testcase_22 | AC | 52 ms
19,284 KB |
testcase_23 | AC | 181 ms
21,416 KB |
testcase_24 | AC | 370 ms
21,536 KB |
testcase_25 | AC | 77 ms
19,644 KB |
testcase_26 | AC | 121 ms
19,880 KB |
testcase_27 | AC | 233 ms
20,584 KB |
testcase_28 | AC | 198 ms
20,400 KB |
testcase_29 | AC | 142 ms
20,004 KB |
testcase_30 | AC | 169 ms
20,260 KB |
testcase_31 | AC | 338 ms
23,076 KB |
testcase_32 | AC | 255 ms
21,268 KB |
testcase_33 | AC | 100 ms
20,388 KB |
testcase_34 | AC | 277 ms
20,772 KB |
testcase_35 | AC | 242 ms
22,568 KB |
testcase_36 | AC | 95 ms
20,648 KB |
testcase_37 | AC | 436 ms
22,948 KB |
testcase_38 | AC | 268 ms
21,100 KB |
testcase_39 | AC | 162 ms
21,408 KB |
testcase_40 | AC | 194 ms
21,096 KB |
testcase_41 | AC | 167 ms
20,000 KB |
testcase_42 | AC | 395 ms
22,180 KB |
testcase_43 | AC | 217 ms
20,644 KB |
testcase_44 | AC | 230 ms
21,124 KB |
testcase_45 | AC | 373 ms
21,872 KB |
testcase_46 | AC | 132 ms
19,872 KB |
testcase_47 | AC | 141 ms
22,300 KB |
testcase_48 | AC | 343 ms
21,792 KB |
testcase_49 | AC | 408 ms
22,924 KB |
testcase_50 | AC | 360 ms
21,924 KB |
testcase_51 | AC | 146 ms
22,156 KB |
testcase_52 | AC | 150 ms
20,092 KB |
testcase_53 | AC | 92 ms
19,832 KB |
testcase_54 | AC | 250 ms
22,976 KB |
testcase_55 | AC | 243 ms
21,668 KB |
testcase_56 | AC | 166 ms
20,132 KB |
testcase_57 | AC | 447 ms
23,036 KB |
testcase_58 | AC | 221 ms
22,552 KB |
testcase_59 | AC | 156 ms
20,136 KB |
testcase_60 | AC | 415 ms
22,880 KB |
testcase_61 | AC | 167 ms
20,776 KB |
testcase_62 | AC | 345 ms
22,564 KB |
testcase_63 | AC | 226 ms
23,136 KB |
testcase_64 | AC | 223 ms
21,416 KB |
testcase_65 | AC | 97 ms
19,748 KB |
testcase_66 | AC | 175 ms
20,640 KB |
testcase_67 | AC | 150 ms
20,256 KB |
testcase_68 | AC | 111 ms
19,672 KB |
testcase_69 | AC | 160 ms
20,260 KB |
testcase_70 | AC | 273 ms
21,540 KB |
testcase_71 | AC | 169 ms
21,672 KB |
testcase_72 | AC | 289 ms
22,040 KB |
testcase_73 | AC | 218 ms
23,072 KB |
testcase_74 | AC | 120 ms
22,800 KB |
testcase_75 | AC | 191 ms
22,048 KB |
testcase_76 | AC | 158 ms
21,548 KB |
testcase_77 | AC | 189 ms
22,672 KB |
testcase_78 | AC | 277 ms
21,896 KB |
testcase_79 | AC | 318 ms
22,688 KB |
testcase_80 | AC | 273 ms
21,540 KB |
testcase_81 | AC | 139 ms
22,308 KB |
testcase_82 | AC | 179 ms
22,992 KB |
testcase_83 | AC | 251 ms
21,336 KB |
testcase_84 | AC | 163 ms
21,576 KB |
testcase_85 | AC | 318 ms
23,016 KB |
testcase_86 | AC | 205 ms
22,344 KB |
testcase_87 | AC | 275 ms
22,824 KB |
testcase_88 | AC | 135 ms
22,440 KB |
testcase_89 | AC | 226 ms
21,180 KB |
testcase_90 | AC | 128 ms
23,208 KB |
testcase_91 | AC | 120 ms
23,112 KB |
testcase_92 | AC | 119 ms
23,156 KB |
testcase_93 | AC | 126 ms
23,080 KB |
testcase_94 | AC | 118 ms
23,204 KB |
testcase_95 | AC | 566 ms
23,252 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) // Sieve of Eratosthenes // (*this)[i] = (divisor of i, greater than 1) // Example: [0, 1, 2, 3, 2, 5, 3, 7, 2, 3, 2, 11, ...] // Complexity: Space O(MAXN), Time (construction) O(MAXNloglogMAXN) struct SieveOfEratosthenes : std::vector<int> { std::vector<int> primes; SieveOfEratosthenes(int MAXN) : std::vector<int>(MAXN + 1) { std::iota(begin(), end(), 0); for (int i = 2; i <= MAXN; i++) { if ((*this)[i] == i) { primes.push_back(i); for (int j = i; j <= MAXN; j += i) (*this)[j] = i; } } } using T = long long int; // Prime factorization for x <= MAXN^2 // Complexity: O(log x) (x <= MAXN) // O(MAXN / logMAXN) (MAXN < x <= MAXN^2) std::map<T, int> Factorize(T x) { assert(x <= 1LL * (int(size()) - 1) * (int(size()) - 1)); std::map<T, int> ret; if (x < int(size())) { while (x > 1) { ret[(*this)[x]]++; x /= (*this)[x]; } } else { for (auto p : primes) { while (!(x % p)) x /= p, ret[p]++; if (x == 1) break; } if (x > 1) ret[x]++; } return ret; } std::vector<T> Divisors(T x) { std::vector<T> ret{1}; for (auto p : Factorize(x)) { int n = ret.size(); for (int i = 0; i < n; i++) { for (T a = 1, d = 1; d <= p.second; d++) { a *= p.first; ret.push_back(ret[i] * a); } } } return ret; // Not sorted } }; SieveOfEratosthenes sieve(1000010); int main() { int N, M; cin >> N >> M; vector<int> A(M); for (auto &a : A) cin >> a; lint ret = -accumulate(ALL(A), 0LL); constexpr int L = 1e6 + 10; vector<int> Phi(L + 1); iota(ALL(Phi), 0); FOR(p, 2, L + 1) { if (Phi[p] == p) { Phi[p] = p - 1; for (int i = p * 2; i <= L; i += p) { Phi[i] = Phi[i] / p * (p - 1); } } } vector<lint> memo(L + 1, -1); for (auto a : A) { lint ans = memo[a]; if (ans < 0) { ans = 0; auto v = sieve.Divisors(a); for (auto d : v) ans += d * Phi[a / d]; } memo[a] = ans; ret += ans; } cout << ret << '\n'; }