Submission #53363741


Source Code Expand

/*
You have the right to work only but never to its fruits.
Let not the fruits of action be your motive, nor let your attachment be to inaction.
*/
#include<bits/stdc++.h>
using namespace std;

#define all (v) v.begin(), v.end()
#define ll long long
#define wishOneDay ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define endl '\n';

map<long long, long long> val[10];
const long long mod = 998244353;
long long dp[30];

void solve(){
    long long n;
    cin >> n;
    vector<long long> arr(n);
    for(auto &a : arr)
        cin >> a;

    ll vaL = 1;
    for(int i = 0; i < 25; i++){
        dp[i] = vaL;
        vaL *= 10ll;
        vaL %= mod;
    }

    map<long long, long long> digsLen;

    for(long long i = n - 1; i > -1; i--){
        long long leftNums = i;
        long long currVal = arr[i];
        long long inc = 1, len = 0;
        while( currVal ){
            long long rem = currVal % 10;
            val[rem][inc] += leftNums;
            currVal /= 10;
            inc *= 10; 
            len += 1;
        }
        for(auto &a : digsLen){
            long long len = a.first, cnt = a.second;
            currVal = arr[i];
            inc = dp[a.first];
            // cout << a.first << endl;
            // cout << inc << endl;
            while( currVal ){
                long long rem = currVal % 10ll;
                val[rem][inc] += a.second;
                currVal /= 10ll;
                inc *= 10ll; 
            }
        }
        digsLen[len] += 1;
    }
    long long finalCnt = 0;
    for(long long i = 0; i < 10; i++){
        // cout << i << " => ";
        for(auto &a : val[i]){
            // cout << a.first << " =  " << a.second << ", ";
            while( a.second-- ){
                finalCnt += ((i % mod) * (a.first % mod)) % mod;
                finalCnt %= mod;
            }
        }
        // cout << endl;
    }
    cout << finalCnt;
}

int main(){

    wishOneDay

    long long tc = 1;
    // cin >> tc;
    while( tc-- ) solve(), cout << endl;
    return 0;

}

Submission Info

Submission Time
Task D - Another Sigma Problem
User prabhxs
Language C++ 20 (gcc 12.2)
Score 0
Code Size 2113 Byte
Status TLE
Exec Time 2210 ms
Memory 4912 KiB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:45:23: warning: unused variable ‘len’ [-Wunused-variable]
   45 |             long long len = a.first, cnt = a.second;
      |                       ^~~
Main.cpp:45:38: warning: unused variable ‘cnt’ [-Wunused-variable]
   45 |             long long len = a.first, cnt = a.second;
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 2
AC × 3
TLE × 19
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3544 KiB
00_sample_02.txt AC 1 ms 3548 KiB
01_test_01.txt TLE 2207 ms 4808 KiB
01_test_02.txt TLE 2207 ms 4904 KiB
01_test_03.txt TLE 2207 ms 4908 KiB
01_test_04.txt TLE 2207 ms 4728 KiB
01_test_05.txt TLE 2207 ms 4724 KiB
01_test_06.txt TLE 2208 ms 4744 KiB
01_test_07.txt TLE 2210 ms 4772 KiB
01_test_08.txt TLE 2207 ms 4728 KiB
01_test_09.txt TLE 2207 ms 4752 KiB
01_test_10.txt TLE 2207 ms 4744 KiB
01_test_11.txt TLE 2207 ms 4708 KiB
01_test_12.txt TLE 2207 ms 4800 KiB
01_test_13.txt TLE 2207 ms 4340 KiB
01_test_14.txt TLE 2207 ms 3896 KiB
01_test_15.txt TLE 2207 ms 3824 KiB
01_test_16.txt TLE 2207 ms 3820 KiB
01_test_17.txt AC 1 ms 3616 KiB
01_test_18.txt TLE 2207 ms 4912 KiB
01_test_19.txt TLE 2207 ms 4724 KiB
01_test_20.txt TLE 2207 ms 4804 KiB