Submission #39727752


Source Code Expand

#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;

ll f(ll x)
{
    ll sum = 0;
    while (x)
    {
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll ans = 0;
    ll a[n];
    vector<int> b[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    bool br = 0;
    for (int i = 0; i < n; i++)
    {
        ans += f(a[i]) * n;
    }
    ans *= 2;
    if (br)
    {
        ans = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j <n; j++)
            {
                ans += f(a[i]);
                ans += f(a[j]);
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        ll x = a[i];
        while (x)
        {
            b[i].push_back(x % 10);
            x /= 10;
        }
    }
    ll carry = 0;
    ll pw = 10;
    for (int i = 0; i < 15; i++)
    {
        vector<ll> cur;
        for (int j = 0; j < n; j++)
        {
            cur.push_back(a[j] % pw);
        }
        sort(cur.begin(), cur.end());
        int p = 0;
        for (int j = n - 1; j >= 0; j--)
        {
            while (p < cur.size() && cur[j] + cur[p] < pw)
                p++;
            int add = cur.size() - p;
            carry += add;
        }
        pw *= 10;
    }
    cout << ans - 9 * 1ll * carry;
    return 0;
}
/*
 909
 101
1010
*/

Submission Info

Submission Time
Task C - All Pair Digit Sums
User GrgaExe
Language C++ (GCC 9.2.1)
Score 500
Code Size 1656 Byte
Status AC
Exec Time 297 ms
Memory 28716 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:73:22: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   73 |             while (p < cur.size() && cur[j] + cur[p] < pw)
      |                    ~~^~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 27
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 05_small_digit_01.txt, 05_small_digit_02.txt, 06_large_digit_01.txt, 06_large_digit_02.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 17 ms 3564 KiB
01_sample_02.txt AC 2 ms 3552 KiB
01_sample_03.txt AC 2 ms 3472 KiB
02_small_01.txt AC 2 ms 3552 KiB
02_small_02.txt AC 1 ms 3472 KiB
02_small_03.txt AC 2 ms 3524 KiB
02_small_04.txt AC 2 ms 3436 KiB
02_small_05.txt AC 2 ms 3456 KiB
02_small_06.txt AC 2 ms 3528 KiB
02_small_07.txt AC 4 ms 3516 KiB
02_small_08.txt AC 3 ms 3480 KiB
02_small_09.txt AC 2 ms 3528 KiB
02_small_10.txt AC 2 ms 3448 KiB
03_rand_1_01.txt AC 297 ms 28648 KiB
03_rand_1_02.txt AC 296 ms 28604 KiB
03_rand_1_03.txt AC 296 ms 28708 KiB
03_rand_1_04.txt AC 297 ms 28716 KiB
03_rand_1_05.txt AC 296 ms 28560 KiB
04_rand_2_01.txt AC 269 ms 24492 KiB
04_rand_2_02.txt AC 269 ms 24548 KiB
04_rand_2_03.txt AC 269 ms 24384 KiB
04_rand_2_04.txt AC 269 ms 24416 KiB
04_rand_2_05.txt AC 268 ms 24460 KiB
05_small_digit_01.txt AC 271 ms 28640 KiB
05_small_digit_02.txt AC 269 ms 28576 KiB
06_large_digit_01.txt AC 270 ms 28632 KiB
06_large_digit_02.txt AC 271 ms 28636 KiB