9462022-02-03 20:37:00nmarciSzámjegy keveréscpp11Time limit exceeded 22/40342ms1880 KiB
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <list>
using namespace std;
using ll = long long int;

int main(){
    string s;
    cin >> s;
    int answ = 0;
    if(s.size() > 1){
        while(s.size() > 1){
            //cerr << s << endl;
            sort(s.begin(), s.end());
            int i = lower_bound(s.begin(), s.end(), '1') - s.begin();
            swap(s[0],s[i]);
            i = s.size() - 1;
            if(s[i] == '0'){
                s = s.substr(0,1) + string(s.size() - 1, '9');
                --s[0];
            }
            else{
                --s[i];
            }
            while(*s.begin() == '0'){
                s.erase(s.begin());
            }
            ++answ;
        }
        answ += atoi(s.c_str());
        cout << answ << endl;
    }
    else{
        cout << atoi(s.c_str()) << endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base22/40
1Accepted0/02ms1740 KiB
2Accepted0/01ms1784 KiB
3Accepted0/021ms1852 KiB
4Accepted2/21ms1848 KiB
5Accepted2/21ms1852 KiB
6Accepted2/21ms1860 KiB
7Accepted2/21ms1860 KiB
8Accepted2/21ms1860 KiB
9Accepted2/21ms1868 KiB
10Accepted2/21ms1868 KiB
11Accepted4/41ms1872 KiB
12Accepted4/41ms1880 KiB
13Time limit exceeded0/2293ms1036 KiB
14Time limit exceeded0/2298ms1048 KiB
15Time limit exceeded0/2296ms1056 KiB
16Time limit exceeded0/2342ms1060 KiB
17Time limit exceeded0/2298ms1092 KiB
18Time limit exceeded0/2273ms1100 KiB
19Time limit exceeded0/3296ms1056 KiB
20Time limit exceeded0/3294ms1188 KiB