QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#801203 | #2945. 1's For All | LaVuna47# | WA | 33ms | 22192kb | C++17 | 2.0kb | 2024-12-06 19:30:07 | 2024-12-06 19:30:08 |
Judging History
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 f(int num)
{
if(num==0)
return 0;
if(dp[num]!=-1)
return dp[num];
int res=1e4;
FOR(i,0,sz(ones))
{
if(num-ones[i] >= 0)
res=min(res,i+1+f(num-ones[i]));
}
for(auto d:divs[num])
{
if(d!=1 && num/d!=1)
res=min(res,f(d)+f(num/d));
}
return dp[num]=res;
}
int solve()
{
int num;
if(!(cin>>num))
return 1;
cout << f(num)<<"\n";
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
for(auto&item:dp)item=-1;
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: 33ms
memory: 22192kb
input:
100000
output:
12
result:
ok single line: '12'
Test #2:
score: -100
Wrong Answer
time: 18ms
memory: 21584kb
input:
90909
output:
16
result:
wrong answer 1st lines differ - expected: '13', found: '16'