Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- //speed coding
- #define mp make_pair
- #define cve(tpy) for (auto i : tpy) {for(auto j : i){cout << j << " "; }cout << "\n";} ;
- #define f first
- #define s second
- #define loop(i, x, n) for (int i = x; i < n; i++)
- #define joop(x, n) for (ll j = x; j < n; j++)
- #define lp(n) for (ll i = 0; i < n; i++)
- #define err cout << "ERROR" << endl;
- #define all(x) x.begin(), x.end()
- #define pb push_back
- #define sz(x) x.size()
- #define rndm rng()
- // types
- #define pii pair<int, int>
- #define pll pair<ll, ll>
- #define vvi vector<vector<int>>
- #define vvll vector<vector<ll>>
- typedef long long ll;
- typedef long double ld;
- // types of data
- #define inf 1000000000
- #define infll 1000000000000000000
- #define INF ll(1e18)
- #define md 998244353
- #define mod 1000000009
- //#define K 239017
- #define DEBUG 1
- using namespace std;
- mt19937_64 rng(113113);
- uniform_int_distribution<ll> drist;
- void solve() {
- int a, b;
- cin >> a >> b;
- vector<pii > p(b + 1, mp(inf, -1));
- if (a > b) {
- cout << "-1\n";
- return;
- }
- p[a] = mp(0, -1);
- loop(i, a, b + 1) {
- if (i * 2 <= b) {
- int x = min(p[i].f + 1, p[2 * i].f);
- if (x == p[i].f + 1) {
- p[2 * i] = mp(p[i].f + 1, 0);
- }
- }
- if (i * 10 + 1 <= b) {
- int x = min(p[i].f + 1, p[i * 10 + 1].f);
- if (x == p[i].f + 1) {
- p[i * 10 + 1] = mp(p[i].f + 1, 1);
- }
- }
- }
- for (auto i: p) {
- // cout << i << " ";
- }
- if(p[b].f != inf){
- cout << p[b].f << "\n";
- vector<int> ans;
- while(b != a){
- if(p[b].s == 0 ){
- ans.pb(0);
- b/=2;
- }else if(p[b].s == 1 ){
- ans.pb(1);
- b= (b-1)/10;
- }
- }
- reverse(all(ans));
- for(auto i : ans){
- cout << i << " ";
- }
- }
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- #ifdef DEBUG
- freopen("text.txt", "r", stdin);
- #endif
- int t = 1;
- // cin >> t;
- loop(i, 0, t) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment