提出 #54100050


ソースコード 拡げる

/// I am snatchin chains and burnin' tattoos
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i, a, b) for (int i = a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x, y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll

using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;

const int N = 1e6 + 5, A = 26 * 26, LG = 19, MOD = (119 << 23) + 1;
const long double PI = acos(-1);
const long double EPS = 1e-7;
int cnt[N];
void doWork() {

    int n;
    cin >> n;
    f(i, 0, n) {
        int x;
        cin >> x;
        cnt[x] += 1;
    }
    int ans = 0;
    f(i, 1, N) cnt[i] += cnt[i - 1];
    for (int i = 1; i < N; i++)
    {
        int cur = cnt[i] - cnt[i - 1];
        ans -= cur * cur;
        ans += cur * (cur - 1) / 2;
        for (int j = 1; i * j < N; j++) {
            int add = cnt[min(N - 1, i * j + i - 1)] - cnt[i * j - 1];
            ans += cur * j * add;
        }

    }
    cout << ans << endl;

}


int32_t main() {
#ifdef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

    int t = 1;
    // cin >> t;
    while (t--) {
        doWork();
    }
}

提出情報

提出日時
問題 E - Max/Min
ユーザ triplem5ds
言語 C++ 20 (gcc 12.2)
得点 475
コード長 1437 Byte
結果 AC
実行時間 53 ms
メモリ 11420 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 3
AC × 25
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All min_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
min_01.txt AC 34 ms 11344 KiB
random_01.txt AC 46 ms 11216 KiB
random_02.txt AC 38 ms 11156 KiB
random_03.txt AC 46 ms 11272 KiB
random_04.txt AC 44 ms 11212 KiB
random_05.txt AC 44 ms 11148 KiB
random_06.txt AC 53 ms 11372 KiB
random_07.txt AC 47 ms 11216 KiB
random_08.txt AC 35 ms 11224 KiB
random_09.txt AC 47 ms 11364 KiB
random_10.txt AC 39 ms 11280 KiB
random_11.txt AC 45 ms 11348 KiB
random_12.txt AC 44 ms 11220 KiB
random_13.txt AC 46 ms 11364 KiB
random_14.txt AC 45 ms 11216 KiB
random_15.txt AC 46 ms 11376 KiB
random_16.txt AC 39 ms 11284 KiB
random_17.txt AC 39 ms 11420 KiB
random_18.txt AC 43 ms 11280 KiB
random_19.txt AC 42 ms 11232 KiB
random_20.txt AC 43 ms 11276 KiB
random_21.txt AC 53 ms 11220 KiB
sample_01.txt AC 34 ms 11412 KiB
sample_02.txt AC 34 ms 11208 KiB
sample_03.txt AC 34 ms 11280 KiB