Submission #71156225


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

long long pw(long long a, long long b, long long m) {
    long long res = 1;
    a %= m;
    while (b > 0) {
        if (b % 2 == 1) res = (res * a) % m;
        a = (a * a) % m;
        b /= 2;
    }
    return res;
}

int len(long long n) {
    string s = to_string(n);
    return s.length();
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    long long m;
    cin >> n >> m;

    vector<long long> a(n);
    vector<long long> v[11];

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        v[len(a[i])].push_back(a[i] % m);
    }

    for (int i = 1; i <= 10; i++) {
        sort(v[i].begin(), v[i].end());
    }

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= 10; j++) {
            if (v[j].empty()) continue;

            long long mul = pw(10, j, m);
            long long cur = (a[i] % m * mul) % m;
            long long tar = (m - cur) % m;

            ans += upper_bound(v[j].begin(), v[j].end(), tar) - lower_bound(v[j].begin(), v[j].end(), tar);
        }
    }

    cout << ans;
    return 0;
}

Submission Info

Submission Time
Task D - 183183
User Luongdung
Language C++23 (GCC 15.2.0)
Score 400
Code Size 1189 Byte
Status AC
Exec Time 158 ms
Memory 7244 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 25
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3520 KiB
00_sample_01.txt AC 1 ms 3628 KiB
00_sample_02.txt AC 1 ms 3516 KiB
00_sample_03.txt AC 1 ms 3572 KiB
01_random_00.txt AC 1 ms 3472 KiB
01_random_01.txt AC 1 ms 3616 KiB
01_random_02.txt AC 1 ms 3460 KiB
01_random_03.txt AC 1 ms 3588 KiB
01_random_04.txt AC 20 ms 7024 KiB
01_random_05.txt AC 21 ms 4192 KiB
01_random_06.txt AC 67 ms 5544 KiB
01_random_07.txt AC 43 ms 5364 KiB
01_random_08.txt AC 40 ms 6904 KiB
01_random_09.txt AC 103 ms 6988 KiB
01_random_10.txt AC 49 ms 7156 KiB
01_random_11.txt AC 95 ms 7092 KiB
01_random_12.txt AC 50 ms 7160 KiB
01_random_13.txt AC 12 ms 3840 KiB
01_random_14.txt AC 151 ms 5600 KiB
01_random_15.txt AC 85 ms 6152 KiB
01_random_16.txt AC 44 ms 5600 KiB
01_random_17.txt AC 12 ms 3880 KiB
01_random_18.txt AC 158 ms 6644 KiB
01_random_19.txt AC 39 ms 7244 KiB
01_random_20.txt AC 8 ms 4264 KiB