結果

問題 No.1262 グラフを作ろう!
ユーザー yuto1115yuto1115
提出日時 2020-10-16 23:36:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 3,000 ms
コード長 2,199 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 202,988 KB
実行使用メモリ 18,792 KB
最終ジャッジ日時 2023-09-28 05:48:20
合計ジャッジ時間 20,397 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
11,692 KB
testcase_01 AC 84 ms
9,628 KB
testcase_02 AC 128 ms
14,020 KB
testcase_03 AC 103 ms
9,316 KB
testcase_04 AC 68 ms
12,660 KB
testcase_05 AC 80 ms
11,168 KB
testcase_06 AC 75 ms
14,252 KB
testcase_07 AC 21 ms
5,472 KB
testcase_08 AC 112 ms
15,044 KB
testcase_09 AC 68 ms
7,252 KB
testcase_10 AC 64 ms
8,464 KB
testcase_11 AC 122 ms
15,980 KB
testcase_12 AC 107 ms
10,964 KB
testcase_13 AC 107 ms
9,572 KB
testcase_14 AC 63 ms
9,032 KB
testcase_15 AC 53 ms
6,268 KB
testcase_16 AC 113 ms
14,244 KB
testcase_17 AC 99 ms
12,480 KB
testcase_18 AC 137 ms
15,252 KB
testcase_19 AC 60 ms
11,684 KB
testcase_20 AC 99 ms
15,696 KB
testcase_21 AC 136 ms
14,244 KB
testcase_22 AC 51 ms
10,812 KB
testcase_23 AC 70 ms
7,732 KB
testcase_24 AC 116 ms
14,724 KB
testcase_25 AC 38 ms
8,044 KB
testcase_26 AC 49 ms
9,248 KB
testcase_27 AC 91 ms
13,408 KB
testcase_28 AC 83 ms
11,888 KB
testcase_29 AC 73 ms
12,612 KB
testcase_30 AC 60 ms
9,572 KB
testcase_31 AC 123 ms
12,352 KB
testcase_32 AC 85 ms
10,580 KB
testcase_33 AC 32 ms
5,424 KB
testcase_34 AC 111 ms
15,692 KB
testcase_35 AC 101 ms
9,844 KB
testcase_36 AC 35 ms
5,208 KB
testcase_37 AC 141 ms
15,456 KB
testcase_38 AC 93 ms
12,740 KB
testcase_39 AC 65 ms
7,332 KB
testcase_40 AC 66 ms
8,648 KB
testcase_41 AC 97 ms
13,532 KB
testcase_42 AC 130 ms
15,448 KB
testcase_43 AC 79 ms
11,428 KB
testcase_44 AC 80 ms
10,876 KB
testcase_45 AC 133 ms
15,984 KB
testcase_46 AC 89 ms
15,304 KB
testcase_47 AC 69 ms
7,064 KB
testcase_48 AC 114 ms
14,320 KB
testcase_49 AC 137 ms
14,944 KB
testcase_50 AC 126 ms
15,760 KB
testcase_51 AC 80 ms
8,320 KB
testcase_52 AC 88 ms
14,656 KB
testcase_53 AC 32 ms
6,616 KB
testcase_54 AC 113 ms
11,120 KB
testcase_55 AC 91 ms
10,688 KB
testcase_56 AC 79 ms
13,200 KB
testcase_57 AC 155 ms
17,292 KB
testcase_58 AC 101 ms
10,160 KB
testcase_59 AC 82 ms
13,728 KB
testcase_60 AC 145 ms
16,452 KB
testcase_61 AC 60 ms
8,856 KB
testcase_62 AC 126 ms
13,796 KB
testcase_63 AC 112 ms
10,572 KB
testcase_64 AC 84 ms
10,432 KB
testcase_65 AC 46 ms
9,048 KB
testcase_66 AC 64 ms
9,180 KB
testcase_67 AC 61 ms
10,432 KB
testcase_68 AC 84 ms
14,916 KB
testcase_69 AC 61 ms
9,776 KB
testcase_70 AC 125 ms
16,360 KB
testcase_71 AC 103 ms
13,188 KB
testcase_72 AC 136 ms
16,820 KB
testcase_73 AC 142 ms
14,996 KB
testcase_74 AC 119 ms
12,636 KB
testcase_75 AC 117 ms
13,932 KB
testcase_76 AC 100 ms
13,188 KB
testcase_77 AC 118 ms
13,148 KB
testcase_78 AC 113 ms
14,176 KB
testcase_79 AC 147 ms
17,080 KB
testcase_80 AC 125 ms
16,552 KB
testcase_81 AC 115 ms
12,948 KB
testcase_82 AC 135 ms
14,192 KB
testcase_83 AC 120 ms
15,708 KB
testcase_84 AC 103 ms
13,260 KB
testcase_85 AC 154 ms
17,276 KB
testcase_86 AC 121 ms
13,944 KB
testcase_87 AC 142 ms
15,956 KB
testcase_88 AC 116 ms
12,940 KB
testcase_89 AC 130 ms
15,260 KB
testcase_90 AC 166 ms
18,600 KB
testcase_91 AC 166 ms
18,756 KB
testcase_92 AC 167 ms
18,560 KB
testcase_93 AC 174 ms
18,616 KB
testcase_94 AC 165 ms
18,496 KB
testcase_95 AC 164 ms
18,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vi a(m);
    cin >> a;
    ll ans = 0;
    ans -= accumulate(all(a), 0LL);
    int mx = *max_element(all(a));
    vl v(mx + 1);
    vi cnt(mx + 1);
    rep(i, m) cnt[a[i]]++;
    for (int i = mx; i > 0; i--) {
        for (int j = i; j <= mx; j += i) {
            v[i] += (ll) cnt[j] * (j / i);
        }
        for (int j = i * 2; j <= mx; j += i) {
            v[i] -= v[j];
        }
        ans += v[i] * i;
    }
    cout << ans << endl;
}
0