結果

問題 No.1262 グラフを作ろう!
ユーザー fastmathfastmath
提出日時 2020-10-16 23:40:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,338 ms / 3,000 ms
コード長 1,706 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 201,704 KB
実行使用メモリ 131,396 KB
最終ジャッジ日時 2023-09-28 06:08:37
合計ジャッジ時間 141,068 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,891 ms
127,200 KB
testcase_01 AC 1,734 ms
126,304 KB
testcase_02 AC 1,981 ms
130,092 KB
testcase_03 AC 1,721 ms
125,024 KB
testcase_04 AC 1,470 ms
129,748 KB
testcase_05 AC 1,729 ms
127,792 KB
testcase_06 AC 1,463 ms
130,844 KB
testcase_07 AC 1,510 ms
124,476 KB
testcase_08 AC 1,874 ms
130,880 KB
testcase_09 AC 1,547 ms
124,228 KB
testcase_10 AC 1,728 ms
125,964 KB
testcase_11 AC 1,930 ms
130,912 KB
testcase_12 AC 1,843 ms
126,532 KB
testcase_13 AC 1,691 ms
125,192 KB
testcase_14 AC 1,675 ms
126,652 KB
testcase_15 AC 1,438 ms
123,748 KB
testcase_16 AC 1,892 ms
130,616 KB
testcase_17 AC 1,718 ms
128,112 KB
testcase_18 AC 2,051 ms
130,544 KB
testcase_19 AC 1,434 ms
130,044 KB
testcase_20 AC 1,557 ms
131,160 KB
testcase_21 AC 1,979 ms
128,648 KB
testcase_22 AC 1,400 ms
129,876 KB
testcase_23 AC 1,567 ms
124,996 KB
testcase_24 AC 1,834 ms
130,496 KB
testcase_25 AC 1,478 ms
126,628 KB
testcase_26 AC 1,532 ms
127,120 KB
testcase_27 AC 1,702 ms
129,456 KB
testcase_28 AC 1,608 ms
130,136 KB
testcase_29 AC 1,552 ms
130,232 KB
testcase_30 AC 1,558 ms
126,928 KB
testcase_31 AC 1,806 ms
127,084 KB
testcase_32 AC 1,707 ms
127,184 KB
testcase_33 AC 1,437 ms
123,916 KB
testcase_34 AC 1,745 ms
131,048 KB
testcase_35 AC 1,625 ms
125,604 KB
testcase_36 AC 1,404 ms
123,668 KB
testcase_37 AC 2,023 ms
130,372 KB
testcase_38 AC 1,729 ms
129,908 KB
testcase_39 AC 1,517 ms
124,576 KB
testcase_40 AC 1,578 ms
125,740 KB
testcase_41 AC 1,571 ms
129,956 KB
testcase_42 AC 1,998 ms
130,752 KB
testcase_43 AC 1,670 ms
129,772 KB
testcase_44 AC 1,686 ms
127,396 KB
testcase_45 AC 1,948 ms
130,856 KB
testcase_46 AC 1,515 ms
131,396 KB
testcase_47 AC 1,454 ms
123,836 KB
testcase_48 AC 1,830 ms
130,348 KB
testcase_49 AC 1,975 ms
130,108 KB
testcase_50 AC 2,007 ms
130,444 KB
testcase_51 AC 1,524 ms
124,284 KB
testcase_52 AC 1,589 ms
130,544 KB
testcase_53 AC 1,457 ms
125,244 KB
testcase_54 AC 1,685 ms
125,848 KB
testcase_55 AC 1,740 ms
126,372 KB
testcase_56 AC 1,539 ms
130,376 KB
testcase_57 AC 1,978 ms
130,544 KB
testcase_58 AC 1,536 ms
125,344 KB
testcase_59 AC 1,477 ms
130,320 KB
testcase_60 AC 1,897 ms
130,368 KB
testcase_61 AC 1,473 ms
125,636 KB
testcase_62 AC 1,856 ms
129,572 KB
testcase_63 AC 1,738 ms
125,400 KB
testcase_64 AC 1,750 ms
126,208 KB
testcase_65 AC 1,507 ms
126,748 KB
testcase_66 AC 1,607 ms
125,968 KB
testcase_67 AC 1,553 ms
129,224 KB
testcase_68 AC 1,510 ms
131,092 KB
testcase_69 AC 1,546 ms
127,024 KB
testcase_70 AC 1,842 ms
128,776 KB
testcase_71 AC 1,646 ms
127,028 KB
testcase_72 AC 1,905 ms
128,540 KB
testcase_73 AC 1,691 ms
127,152 KB
testcase_74 AC 1,418 ms
123,468 KB
testcase_75 AC 1,675 ms
127,260 KB
testcase_76 AC 1,612 ms
127,184 KB
testcase_77 AC 1,624 ms
126,400 KB
testcase_78 AC 1,700 ms
127,540 KB
testcase_79 AC 1,968 ms
128,692 KB
testcase_80 AC 1,837 ms
129,160 KB
testcase_81 AC 1,529 ms
126,152 KB
testcase_82 AC 1,594 ms
126,720 KB
testcase_83 AC 1,844 ms
128,676 KB
testcase_84 AC 1,612 ms
127,024 KB
testcase_85 AC 1,904 ms
128,516 KB
testcase_86 AC 1,636 ms
127,340 KB
testcase_87 AC 1,787 ms
128,064 KB
testcase_88 AC 1,477 ms
126,164 KB
testcase_89 AC 1,751 ms
128,220 KB
testcase_90 AC 1,474 ms
125,076 KB
testcase_91 AC 1,479 ms
125,080 KB
testcase_92 AC 1,465 ms
125,404 KB
testcase_93 AC 1,491 ms
125,480 KB
testcase_94 AC 1,462 ms
125,776 KB
testcase_95 AC 2,338 ms
131,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#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;
    ll 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