結果
| 問題 |
No.917 Make One With GCD
|
| ユーザー |
|
| 提出日時 | 2019-09-09 03:01:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 RE * 1 |
| other | AC * 2 WA * 1 RE * 29 |
ソースコード
#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;
}