QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#801220#2945. 1's For AllLaVuna47#AC ✓75ms14644kbC++172.1kb2024-12-06 19:46:052024-12-06 19:46:06

Judging History

This is the latest submission verdict.

  • [2024-12-06 19:46:06]
  • Judged
  • Verdict: AC
  • Time: 75ms
  • Memory: 14644kb
  • [2024-12-06 19:46:05]
  • Submitted

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

#define MAX_N 100010
vector<int> ones={1,11,111,1111,11111};


vector<int> divs[MAX_N];
int dp[MAX_N];

int solve()
{
	int N;
	if(!(cin>>N))
		return 1;
	dp[0]=0,dp[1]=1;
	FOR(num,2,N+1)
	{
		int res=1e4;
		FOR(i,0,sz(ones))
		{
			if(num-ones[i] >= 0)
				res=min(res,i+1+dp[num-ones[i]]);
		}
		for(auto d:divs[num])
		{
			if(d!=1 && num/d!=1)
				res=min(res, dp[d]+dp[num/d]);
		}
		auto s = to_string(num);
		FOR(i,1,sz(s))
		{
			int s1 = stoi(s.substr(0,i));
			int s2 = stoi(s.substr(i));
			if(to_string(s1)+to_string(s2)==s && s2!=0)
			{
				res=min(res,dp[s1] + dp[s2]);
			}
		}
		dp[num]=res;
	}
	cout << dp[N] <<"\n";
    return 0;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1e9;
    FOR(i,1,MAX_N)
	{
		for(int j = i; j < MAX_N; j+=i)
		{
			divs[j].pb(i);
		}
	}
    //cin >> TET;
    for (int i = 1; i <= TET; i++)
    {
        if (solve())
        {
            break;
        }
#ifdef ONPC
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 61ms
memory: 14412kb

input:

100000

output:

12

result:

ok single line: '12'

Test #2:

score: 0
Accepted
time: 61ms
memory: 14324kb

input:

90909

output:

13

result:

ok single line: '13'

Test #3:

score: 0
Accepted
time: 25ms
memory: 14020kb

input:

10101

output:

10

result:

ok single line: '10'

Test #4:

score: 0
Accepted
time: 28ms
memory: 14068kb

input:

10001

output:

11

result:

ok single line: '11'

Test #5:

score: 0
Accepted
time: 58ms
memory: 14388kb

input:

99999

output:

11

result:

ok single line: '11'

Test #6:

score: 0
Accepted
time: 60ms
memory: 14644kb

input:

99998

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 59ms
memory: 14416kb

input:

99997

output:

13

result:

ok single line: '13'

Test #8:

score: 0
Accepted
time: 64ms
memory: 14376kb

input:

99989

output:

17

result:

ok single line: '17'

Test #9:

score: 0
Accepted
time: 74ms
memory: 14620kb

input:

99988

output:

16

result:

ok single line: '16'

Test #10:

score: 0
Accepted
time: 28ms
memory: 14064kb

input:

2

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 62ms
memory: 14416kb

input:

99984

output:

15

result:

ok single line: '15'

Test #12:

score: 0
Accepted
time: 64ms
memory: 14416kb

input:

98069

output:

18

result:

ok single line: '18'

Test #13:

score: 0
Accepted
time: 75ms
memory: 14424kb

input:

96721

output:

10

result:

ok single line: '10'

Test #14:

score: 0
Accepted
time: 69ms
memory: 14308kb

input:

70549

output:

18

result:

ok single line: '18'

Test #15:

score: 0
Accepted
time: 49ms
memory: 14644kb

input:

65621

output:

9

result:

ok single line: '9'

Test #16:

score: 0
Accepted
time: 51ms
memory: 14156kb

input:

44521

output:

8

result:

ok single line: '8'

Test #17:

score: 0
Accepted
time: 42ms
memory: 14188kb

input:

31111

output:

7

result:

ok single line: '7'

Test #18:

score: 0
Accepted
time: 34ms
memory: 14152kb

input:

21111

output:

6

result:

ok single line: '6'

Test #19:

score: 0
Accepted
time: 36ms
memory: 14108kb

input:

20158

output:

17

result:

ok single line: '17'

Test #20:

score: 0
Accepted
time: 41ms
memory: 14292kb

input:

11111

output:

5

result:

ok single line: '5'

Test #21:

score: 0
Accepted
time: 26ms
memory: 14232kb

input:

12

output:

3

result:

ok single line: '3'

Test #22:

score: 0
Accepted
time: 30ms
memory: 14296kb

input:

9609

output:

16

result:

ok single line: '16'

Test #23:

score: 0
Accepted
time: 28ms
memory: 14088kb

input:

5738

output:

15

result:

ok single line: '15'

Test #24:

score: 0
Accepted
time: 28ms
memory: 14036kb

input:

2087

output:

14

result:

ok single line: '14'

Test #25:

score: 0
Accepted
time: 27ms
memory: 14048kb

input:

1111

output:

4

result:

ok single line: '4'

Test #26:

score: 0
Accepted
time: 27ms
memory: 14044kb

input:

718

output:

13

result:

ok single line: '13'

Test #27:

score: 0
Accepted
time: 25ms
memory: 13984kb

input:

389

output:

12

result:

ok single line: '12'

Test #28:

score: 0
Accepted
time: 27ms
memory: 14032kb

input:

203

output:

11

result:

ok single line: '11'

Test #29:

score: 0
Accepted
time: 30ms
memory: 14028kb

input:

111

output:

3

result:

ok single line: '3'

Test #30:

score: 0
Accepted
time: 32ms
memory: 14232kb

input:

58

output:

10

result:

ok single line: '10'

Test #31:

score: 0
Accepted
time: 34ms
memory: 14040kb

input:

57

output:

9

result:

ok single line: '9'

Test #32:

score: 0
Accepted
time: 38ms
memory: 14152kb

input:

20

output:

8

result:

ok single line: '8'

Test #33:

score: 0
Accepted
time: 24ms
memory: 14032kb

input:

11

output:

2

result:

ok single line: '2'

Test #34:

score: 0
Accepted
time: 37ms
memory: 14252kb

input:

10

output:

7

result:

ok single line: '7'

Test #35:

score: 0
Accepted
time: 34ms
memory: 14020kb

input:

7

output:

6

result:

ok single line: '6'

Test #36:

score: 0
Accepted
time: 40ms
memory: 14036kb

input:

5

output:

5

result:

ok single line: '5'

Test #37:

score: 0
Accepted
time: 42ms
memory: 14184kb

input:

4

output:

4

result:

ok single line: '4'

Test #38:

score: 0
Accepted
time: 46ms
memory: 14036kb

input:

3

output:

3

result:

ok single line: '3'

Test #39:

score: 0
Accepted
time: 41ms
memory: 14108kb

input:

1

output:

1

result:

ok single line: '1'