結果

問題 No.1262 グラフを作ろう!
ユーザー fastmathfastmath
提出日時 2020-10-16 23:38:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,683 ms / 3,000 ms
コード長 1,729 bytes
コンパイル時間 1,798 ms
コンパイル使用メモリ 202,080 KB
実行使用メモリ 209,716 KB
最終ジャッジ日時 2023-09-28 06:03:47
合計ジャッジ時間 184,124 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,946 ms
201,256 KB
testcase_01 AC 1,791 ms
200,524 KB
testcase_02 AC 2,077 ms
204,976 KB
testcase_03 AC 1,706 ms
196,964 KB
testcase_04 AC 1,523 ms
208,200 KB
testcase_05 AC 1,805 ms
204,196 KB
testcase_06 AC 1,494 ms
209,160 KB
testcase_07 AC 1,526 ms
196,152 KB
testcase_08 AC 1,973 ms
207,272 KB
testcase_09 AC 1,600 ms
195,376 KB
testcase_10 AC 1,740 ms
200,220 KB
testcase_11 AC 2,066 ms
209,160 KB
testcase_12 AC 1,916 ms
200,996 KB
testcase_13 AC 1,826 ms
197,336 KB
testcase_14 AC 1,766 ms
200,716 KB
testcase_15 AC 1,526 ms
194,568 KB
testcase_16 AC 1,971 ms
206,104 KB
testcase_17 AC 1,902 ms
204,680 KB
testcase_18 AC 2,271 ms
206,000 KB
testcase_19 AC 1,624 ms
205,476 KB
testcase_20 AC 1,832 ms
209,444 KB
testcase_21 AC 2,180 ms
205,188 KB
testcase_22 AC 1,489 ms
205,084 KB
testcase_23 AC 1,684 ms
196,872 KB
testcase_24 AC 2,016 ms
206,576 KB
testcase_25 AC 1,488 ms
201,152 KB
testcase_26 AC 1,519 ms
201,452 KB
testcase_27 AC 1,856 ms
206,140 KB
testcase_28 AC 1,802 ms
205,100 KB
testcase_29 AC 1,584 ms
205,912 KB
testcase_30 AC 1,577 ms
201,424 KB
testcase_31 AC 1,987 ms
201,412 KB
testcase_32 AC 1,853 ms
201,572 KB
testcase_33 AC 1,495 ms
194,748 KB
testcase_34 AC 1,802 ms
209,164 KB
testcase_35 AC 1,695 ms
199,904 KB
testcase_36 AC 1,426 ms
194,392 KB
testcase_37 AC 2,131 ms
206,272 KB
testcase_38 AC 1,790 ms
205,260 KB
testcase_39 AC 2,342 ms
196,108 KB
testcase_40 AC 2,495 ms
200,040 KB
testcase_41 AC 1,612 ms
206,812 KB
testcase_42 AC 2,091 ms
208,324 KB
testcase_43 AC 1,671 ms
204,596 KB
testcase_44 AC 1,715 ms
201,732 KB
testcase_45 AC 2,112 ms
208,888 KB
testcase_46 AC 1,565 ms
209,716 KB
testcase_47 AC 1,539 ms
194,596 KB
testcase_48 AC 1,902 ms
206,072 KB
testcase_49 AC 2,110 ms
205,616 KB
testcase_50 AC 1,993 ms
207,608 KB
testcase_51 AC 1,593 ms
195,928 KB
testcase_52 AC 1,654 ms
208,364 KB
testcase_53 AC 1,509 ms
198,816 KB
testcase_54 AC 1,735 ms
199,768 KB
testcase_55 AC 1,776 ms
200,288 KB
testcase_56 AC 1,653 ms
205,576 KB
testcase_57 AC 2,334 ms
208,296 KB
testcase_58 AC 1,784 ms
199,212 KB
testcase_59 AC 1,611 ms
207,756 KB
testcase_60 AC 2,244 ms
207,860 KB
testcase_61 AC 1,789 ms
199,540 KB
testcase_62 AC 2,197 ms
204,012 KB
testcase_63 AC 1,805 ms
199,396 KB
testcase_64 AC 1,847 ms
200,108 KB
testcase_65 AC 1,563 ms
200,640 KB
testcase_66 AC 1,724 ms
199,964 KB
testcase_67 AC 1,673 ms
203,324 KB
testcase_68 AC 1,632 ms
208,880 KB
testcase_69 AC 1,749 ms
200,728 KB
testcase_70 AC 2,038 ms
205,044 KB
testcase_71 AC 1,795 ms
200,600 KB
testcase_72 AC 2,045 ms
204,880 KB
testcase_73 AC 1,840 ms
200,820 KB
testcase_74 AC 1,545 ms
195,928 KB
testcase_75 AC 1,801 ms
200,824 KB
testcase_76 AC 1,720 ms
200,384 KB
testcase_77 AC 1,700 ms
199,868 KB
testcase_78 AC 1,844 ms
201,360 KB
testcase_79 AC 2,211 ms
205,132 KB
testcase_80 AC 2,023 ms
205,288 KB
testcase_81 AC 1,643 ms
199,340 KB
testcase_82 AC 1,731 ms
199,880 KB
testcase_83 AC 2,049 ms
205,032 KB
testcase_84 AC 1,706 ms
200,480 KB
testcase_85 AC 2,141 ms
204,872 KB
testcase_86 AC 1,787 ms
200,644 KB
testcase_87 AC 2,070 ms
204,092 KB
testcase_88 AC 1,642 ms
199,108 KB
testcase_89 AC 1,971 ms
204,464 KB
testcase_90 AC 1,564 ms
195,240 KB
testcase_91 AC 1,581 ms
195,360 KB
testcase_92 AC 1,527 ms
195,300 KB
testcase_93 AC 1,584 ms
197,424 KB
testcase_94 AC 1,555 ms
200,168 KB
testcase_95 AC 2,683 ms
209,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 1e6+7;
int pw[N];
bool p[N];
vector <int> d[N];

bool used[N];
int me[N];

int cnt[N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif

    for (int i = 1; i < N; ++i)
        for (int j = i; j < N; j += i)
            d[j].app(i);
    for (int i = 2; i < N; ++i)
        p[i] = 1;
    for (int i = 2; i < N; ++i) {
        if (p[i]) {
            pw[i] = 1;
            for (int j = i * 2; j < N; j += i) {
                p[j] = 0;
                pw[j]++;
            }   
        }
    }                       

    for (int i = 0; i < N; ++i) {
        reverse(all(d[i]));
    }   

    int n, m;
    cin >> n >> m;
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;

        if (used[x]) {
            ans += me[x];
            continue;
        }   

        used[x] = 1;
        for (int a : d[x])
            cnt[a] = 0;
        for (int a : d[x]) {
            cnt[a] += x/a;
            me[x] += cnt[a] * ((x - 1) % a);
            for (int b : d[a])
                if (b < a)
                    cnt[b] -= cnt[a];
        }   
        ans += me[x];
    }   
    cout << ans << endl;

    #ifdef HOME
    cout << Time << endl;
    #endif
}
0