結果
問題 | No.917 Make One With GCD |
ユーザー | ningenMe |
提出日時 | 2019-09-09 03:01:16 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,777 bytes |
コンパイル時間 | 1,814 ms |
コンパイル使用メモリ | 179,884 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 00:30:21 |
合計ジャッジ時間 | 7,136 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | WA | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | AC | 3 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; constexpr long long MOD = 998244353; //divisor O(sqrt(N)) set<long long> Divisor(long long N) { set<long long> ret; for (long long i = 1; i*i <= N; ++i) { if (N%i == 0) { ret.insert(i); ret.insert(N / i); } } return ret; } //Greatest Common Divisor long long GCD(long long a, long long b) { return ((b == 0) ? a : GCD(b, a % b)); } template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;} template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;} template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;} template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;} template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;} template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;} void print(void) {cout << endl;} template <class Head> void print(Head&& head) {cout << head;print();} template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);} int main() { int N,MAX_A = 2000; cin >> N; vector<int> A(N),table(MAX_A+1,0); for(int i = 0; i < N; ++i) cin >> A[i]; // vector<vector<int>> gcd(MAX_A+1,vector<int>(MAX_A+1,0)); // // O(MAX_A*MAX_A*log(MAX_A)) // for(int i = 1; i <= MAX_A; ++i) for(int j = i; j <= MAX_A; ++j) gcd[i][j] = gcd[j][i] = GCD(i,j); long long ans = 0; // O(N*N*N*M+N*M*logM) for(int i = 0; i < N; ++i) { auto d = Divisor(A[i]); int M = d.size(),idx = 0; vector<int> val; // O(M*logM) for(auto& e:d) { table[e] = idx++; val.push_back(e); } vector<vector<long long>> dp(N, vector<long long>(M,0)); dp[i][table[A[i]]] = 1; // O(N*N*M) for(int j = i; j < N; ++j) { for(int k = j + 1; k < N; ++k){ for(int l = 0; l < M; ++l){ // (dp[k][table[gcd[val[l]][A[k]]]] += dp[j][l]) %= MOD; (dp[k][table[GCD(val[l],A[k])]] += dp[j][l]) %= MOD; } } ans += dp[j][table[1]]; } } cout << ans << endl; return 0; }