結果
問題 | No.1262 グラフを作ろう! |
ユーザー | hitonanode |
提出日時 | 2020-10-17 00:08:34 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 559 ms / 3,000 ms |
コード長 | 2,957 bytes |
コンパイル時間 | 2,914 ms |
コンパイル使用メモリ | 227,540 KB |
実行使用メモリ | 23,332 KB |
最終ジャッジ日時 | 2024-07-21 01:13:29 |
合計ジャッジ時間 | 30,777 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 306 ms
22,824 KB |
testcase_01 | AC | 254 ms
21,664 KB |
testcase_02 | AC | 373 ms
22,692 KB |
testcase_03 | AC | 251 ms
22,816 KB |
testcase_04 | AC | 86 ms
19,364 KB |
testcase_05 | AC | 223 ms
21,028 KB |
testcase_06 | AC | 50 ms
19,364 KB |
testcase_07 | AC | 73 ms
19,748 KB |
testcase_08 | AC | 301 ms
21,408 KB |
testcase_09 | AC | 157 ms
21,928 KB |
testcase_10 | AC | 186 ms
21,024 KB |
testcase_11 | AC | 356 ms
21,416 KB |
testcase_12 | AC | 307 ms
22,436 KB |
testcase_13 | AC | 244 ms
22,944 KB |
testcase_14 | AC | 180 ms
20,768 KB |
testcase_15 | AC | 129 ms
21,536 KB |
testcase_16 | AC | 300 ms
21,668 KB |
testcase_17 | AC | 304 ms
21,536 KB |
testcase_18 | AC | 420 ms
22,652 KB |
testcase_19 | AC | 87 ms
19,616 KB |
testcase_20 | AC | 196 ms
20,388 KB |
testcase_21 | AC | 401 ms
22,944 KB |
testcase_22 | AC | 52 ms
19,308 KB |
testcase_23 | AC | 173 ms
21,540 KB |
testcase_24 | AC | 317 ms
21,544 KB |
testcase_25 | AC | 81 ms
19,620 KB |
testcase_26 | AC | 112 ms
19,872 KB |
testcase_27 | AC | 215 ms
20,512 KB |
testcase_28 | AC | 190 ms
20,388 KB |
testcase_29 | AC | 168 ms
20,000 KB |
testcase_30 | AC | 163 ms
20,516 KB |
testcase_31 | AC | 348 ms
23,072 KB |
testcase_32 | AC | 255 ms
21,280 KB |
testcase_33 | AC | 98 ms
20,516 KB |
testcase_34 | AC | 252 ms
20,768 KB |
testcase_35 | AC | 235 ms
22,564 KB |
testcase_36 | AC | 90 ms
20,648 KB |
testcase_37 | AC | 422 ms
22,948 KB |
testcase_38 | AC | 258 ms
21,152 KB |
testcase_39 | AC | 194 ms
21,540 KB |
testcase_40 | AC | 184 ms
21,152 KB |
testcase_41 | AC | 175 ms
20,132 KB |
testcase_42 | AC | 383 ms
22,308 KB |
testcase_43 | AC | 210 ms
20,644 KB |
testcase_44 | AC | 269 ms
21,156 KB |
testcase_45 | AC | 377 ms
21,924 KB |
testcase_46 | AC | 127 ms
19,744 KB |
testcase_47 | AC | 130 ms
22,308 KB |
testcase_48 | AC | 358 ms
21,668 KB |
testcase_49 | AC | 446 ms
22,824 KB |
testcase_50 | AC | 353 ms
22,056 KB |
testcase_51 | AC | 144 ms
22,180 KB |
testcase_52 | AC | 150 ms
20,132 KB |
testcase_53 | AC | 94 ms
19,876 KB |
testcase_54 | AC | 346 ms
23,076 KB |
testcase_55 | AC | 285 ms
21,796 KB |
testcase_56 | AC | 158 ms
20,132 KB |
testcase_57 | AC | 426 ms
23,088 KB |
testcase_58 | AC | 208 ms
22,560 KB |
testcase_59 | AC | 152 ms
20,132 KB |
testcase_60 | AC | 399 ms
22,944 KB |
testcase_61 | AC | 158 ms
20,900 KB |
testcase_62 | AC | 432 ms
22,688 KB |
testcase_63 | AC | 268 ms
23,204 KB |
testcase_64 | AC | 212 ms
21,536 KB |
testcase_65 | AC | 96 ms
19,620 KB |
testcase_66 | AC | 178 ms
20,644 KB |
testcase_67 | AC | 150 ms
20,260 KB |
testcase_68 | AC | 105 ms
19,744 KB |
testcase_69 | AC | 154 ms
20,388 KB |
testcase_70 | AC | 264 ms
21,540 KB |
testcase_71 | AC | 202 ms
21,664 KB |
testcase_72 | AC | 273 ms
22,180 KB |
testcase_73 | AC | 272 ms
23,080 KB |
testcase_74 | AC | 115 ms
22,820 KB |
testcase_75 | AC | 183 ms
22,052 KB |
testcase_76 | AC | 151 ms
21,544 KB |
testcase_77 | AC | 176 ms
22,436 KB |
testcase_78 | AC | 196 ms
21,920 KB |
testcase_79 | AC | 321 ms
22,692 KB |
testcase_80 | AC | 339 ms
21,544 KB |
testcase_81 | AC | 156 ms
22,432 KB |
testcase_82 | AC | 174 ms
23,204 KB |
testcase_83 | AC | 246 ms
21,540 KB |
testcase_84 | AC | 161 ms
21,536 KB |
testcase_85 | AC | 344 ms
23,072 KB |
testcase_86 | AC | 215 ms
22,180 KB |
testcase_87 | AC | 276 ms
22,820 KB |
testcase_88 | AC | 160 ms
22,436 KB |
testcase_89 | AC | 237 ms
21,284 KB |
testcase_90 | AC | 118 ms
23,036 KB |
testcase_91 | AC | 136 ms
23,208 KB |
testcase_92 | AC | 117 ms
23,204 KB |
testcase_93 | AC | 140 ms
23,204 KB |
testcase_94 | AC | 119 ms
23,332 KB |
testcase_95 | AC | 559 ms
23,204 KB |
ソースコード
#pragma GCC optimize("O3") #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 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define REP(i, n) FOR(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); // Euler's totient function // Complexity: O(NlgN) std::vector<int> euler_phi(int N) { std::vector<int> ret(N + 1); std::iota(ret.begin(), ret.end(), 0); for (int p = 2; p <= N; p++) { if (ret[p] == p) { ret[p] = p - 1; for (int i = p * 2; i <= N; i += p) { ret[i] = ret[i] / p * (p - 1); } } } return ret; } int main() { int N, M; cin >> N >> M; vector<int> A(M); for (auto &a : A) cin >> a; lint ret = -accumulate(A.begin(), A.end(), 0LL); constexpr int L = 1e6; auto Phi = euler_phi(L); 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'; }