Submission #23376359


Source Code Expand

// FIRST THINK THEN CODE.

#include<iostream>
#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define cld complex<ld>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vld vector<ld>
#define vvld vector<vector<ld>>
#define vpll vector<pll>
#define vcld vector<cld>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define PI acos(-1)
#define endl "\n"
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define mset(a,val) memset(a,val,sizeof(a));
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
#define FOR(i,a,b)  for(ll i=a;i<=b;i++)
#define FORR(i,a,b)  for(ll i=a;i>=b;i--)
const ll M = 1000000007;
const ll MM = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define ordered_set tree<pll, null_type,less<>, rb_tree_tag,tree_order_statistics_node_update>

ll begtime = clock();
#define end_routine() cerr << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}

const ll N = 2e5 + 5;


ll mulmod(ll a, ll b, ll c) {

  ll ans = 0;
  ll y = a % c;
  while (b) {
    if (b & 1) {
      (ans += y) %= c;
    }
    y = y * 2 % c;
    b >>= 1;
  }
  return ans;

}




ll powMbig(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)//ans = ans * a % m;
      ans = mulmod(ans, a, m);
    //a = a * a % m;
    a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}

ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;

  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    //ans = mulmod(ans, a, m);
    a = a * a % m;
    //a = mulmod(a, a, m);
    b >>= 1;
  }

  return ans;
}



ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}


void OJ() {


#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

}

int main() {

  IOS;

  OJ();


  ll t = 10000;

  ll n; cin >> n;

  vl ans = { -1};

  ll ansa = -1, ansb = -1;
  ld ansrat = -1.0;

  ll mn = 1e9;

  while (t--) {
    ll k = poww(10, 9);
    ll d = poww(10, 8);
    ll lol = rng() % (d) + 16 * poww(10, 8);
    ld phi = (lol * 1.0) / (k);
    //cout << phi << endl;
    //  phi = 1.7;
//    cout << fix(phi, 9) << endl;

    ll rem = 130;

    vl v;
    v.clear();

//     ll n; cin >> n;
    ll x = n, y = n / phi;

//    cout << x << " " << y << endl;
//     ll c = 0;
    while (rem > 0) {
      if (y > x) {
        v.pb(4);
        y -= x;
      }
      else {
        v.pb(3);
        x -= y;
      }
      rem--;
      if (x + y <= rem) {
        break;
      }
      if (min(x, y) <= 0)break;
      // cout << x << " " << y << endl;
      // c++;
    }
//     // cout << x << " " << y << endl;
//     //cout << rem << endl;

    FOR(i, 1, x) {
      v.pb(1);
      if (sz(v) > 130)break;
    }
    FOR(i, 1, y) {
      v.pb(2);
      if (sz(v) > 130)break;
    }

    chmin(mn, sz(v));

//     cout << sz(v) << endl;

    rev(v);

    ll a = 0, b = 0;

    for (auto d : v) {
      if (d == 1)a++;
      else if (d == 2)b++;
      else if (d == 3)a += b;
      else b += a;
      //  cout << a << " " << b << endl;
    }
//   cout << sz(v) << endl;
    //  cout << a << " " << b << endl;
    if (a == n && sz(v) < 130) {
      ans = v;
      ansa = a, ansb = b, ansrat = phi;
      // cout << "YAy" << endl;
      break;
    } else continue;
    // assert(sz(v) <= 130 && a == n);
// cout << a << " " << b << endl;
  }
  // cout << mn << endl;
  // cout << ansa << " " << ansb << endl;
  // cout << fix(ansrat, 9) << endl;
  cout << sz(ans) << endl;
  for (auto d : ans) {
    cout << d << endl;
  }

  return 0;


}

Submission Info

Submission Time
Task C - Calculator
User Saksham_2000
Language C++ (GCC 9.2.1)
Score 600
Code Size 4512 Byte
Status AC
Exec Time 6 ms
Memory 3688 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:159:6: warning: variable ‘ansa’ set but not used [-Wunused-but-set-variable]
  159 |   ll ansa = -1, ansb = -1;
      |      ^~~~
./Main.cpp:159:17: warning: variable ‘ansb’ set but not used [-Wunused-but-set-variable]
  159 |   ll ansa = -1, ansb = -1;
      |                 ^~~~
./Main.cpp:160:6: warning: variable ‘ansrat’ set but not used [-Wunused-but-set-variable]
  160 |   ld ansrat = -1.0;
      |      ^~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 1
AC × 26
Set Name Test Cases
Sample 00-sample-001.txt
All 00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 6 ms 3592 KiB
01-001.txt AC 2 ms 3576 KiB
01-002.txt AC 3 ms 3592 KiB
01-003.txt AC 2 ms 3496 KiB
01-004.txt AC 2 ms 3444 KiB
01-005.txt AC 2 ms 3576 KiB
01-006.txt AC 2 ms 3508 KiB
01-007.txt AC 2 ms 3496 KiB
01-008.txt AC 3 ms 3444 KiB
01-009.txt AC 3 ms 3620 KiB
01-010.txt AC 2 ms 3496 KiB
01-011.txt AC 2 ms 3688 KiB
01-012.txt AC 2 ms 3496 KiB
01-013.txt AC 2 ms 3632 KiB
01-014.txt AC 1 ms 3680 KiB
01-015.txt AC 2 ms 3492 KiB
01-016.txt AC 2 ms 3492 KiB
01-017.txt AC 2 ms 3576 KiB
01-018.txt AC 2 ms 3576 KiB
01-019.txt AC 4 ms 3548 KiB
01-020.txt AC 2 ms 3620 KiB
01-021.txt AC 2 ms 3624 KiB
01-022.txt AC 2 ms 3624 KiB
01-023.txt AC 2 ms 3592 KiB
01-024.txt AC 2 ms 3636 KiB
01-025.txt AC 2 ms 3504 KiB