結果
問題 | No.917 Make One With GCD |
ユーザー | ningenMe |
提出日時 | 2019-09-09 04:51:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,716 bytes |
コンパイル時間 | 1,806 ms |
コンパイル使用メモリ | 178,804 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-28 00:30:59 |
合計ジャッジ時間 | 6,554 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | AC | 3 ms
6,944 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 | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | WA | - |
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; 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)...);} //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)); } //半分全列挙嘘解法 int main() { int N,MAX_A = 1000; cin >> N; vector<int> A(N); for(int i = 0; i < N; ++i) cin >> A[i]; if(N==1){ cout << (A[0]==1) << endl; return 0; } vector<int> L,R; for(int i = 0; i < N/2; ++i) L.push_back(A[i]); for(int i = N/2; i < N; ++i) R.push_back(A[i]); vector<int> cntL(MAX_A+1,0),cntR(MAX_A+1,0); int NL = L.size(), NR = R.size(); for(int i = 1; i < (1<<NL); ++i){ int cnt = 0; for(int j = 0; j < NL; ++j) if(i&(1<<j)) cnt = GCD(cnt,A[j]); cntL[cnt]++; } for(int i = 1; i < (1<<NR); ++i){ int cnt = 0; for(int j = 0; j < NR; ++j) if(i&(1<<j)) cnt = GCD(cnt,A[j+(N/2)]); cntR[cnt]++; } int ans = cntL[1]+cntR[1]+cntL[1]*cntR[1]; int sum = accumulate(cntR.begin(),cntR.end(),0); for(int i = 1; i <= MAX_A; ++i){ int cnt = sum; auto d = Divisor(i); for(auto e:d) cnt -= cntR[e]; cnt *= cntL[i]; ans += cnt; } cout << ans << endl; return 0; }