Submission #2667784


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/







int N;
//---------------------------------------------------------------------------------------------------
int memo[101010];
int f(int cu) {
    if (cu == 0) return 0;
    if (memo[cu]) return memo[cu];

    int res = inf;
    
    // 1yen
    chmin(res, f(cu - 1) + 1);

    // 6yen
    int x = 6;
    while (x <= cu) {
        chmin(res, f(cu - x) + 1);
        x *= 6;
    }

    // 9yen
    x = 9;
    while (x <= cu) {
        chmin(res, f(cu - x) + 1);
        x *= 9;
    }

    return memo[cu] = res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    cout << f(N) << endl;
}

Submission Info

Submission Time
Task C - Strange Bank
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1959 Byte
Status
Exec Time 5 ms
Memory 3712 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 300 / 300 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
01.txt 3 ms 1792 KB
02.txt 5 ms 3712 KB
03.txt 3 ms 1536 KB
04.txt 4 ms 2304 KB
05.txt 3 ms 1920 KB
06.txt 1 ms 256 KB
07.txt 1 ms 256 KB
08.txt 1 ms 256 KB
09.txt 1 ms 256 KB
10.txt 1 ms 256 KB
11.txt 2 ms 1280 KB
12.txt 4 ms 2944 KB
13.txt 2 ms 768 KB
14.txt 1 ms 256 KB
15.txt 1 ms 384 KB
16.txt 5 ms 3712 KB
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 3 ms 1792 KB