Submission #2860135


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

ll sub(ll b, ll a, ll ofs=0) {
#ifdef DEBUG
    fprintf(stderr, "sub(%lld, %lld; %lld)\n", b,a,ofs);
#endif
    // b >= a
    ll q = b/a, r = b%a;
    if (r == 0) {
        ll t = q*2-1;
#ifdef DEBUG
        fprintf(stderr, " + %lldx%lld\n", t,a);
        fprintf(stderr, " = %lld\n", ofs + t*a);
#endif
        return ofs + t*a;
    } else {
        ll t = q*2;
#ifdef DEBUG
        fprintf(stderr, " + %lldx%lld\n", t,a);
#endif
        return sub(a, r, ofs + t*a);
    }
}

ll solve(ll N, ll X){
    /// X < N
    if (X == N-X) {
        return X*3;
    }
    else if (X < N-X) { // 2,3
        // X, N-X
        return sub(N-X, X, N); // 3,2,close
    }
    else { // X > N-X // 3,2
        return sub(X, N-X, N); // 3,2,open
    }
}

int main() {
    ll N, X; cin >> N >> X;
    cout << solve(N,X) << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Mysterious Light
User naoya_t
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2148 Byte
Status
Exec Time 1 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt
Subtask 300 / 300 sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt
All 200 / 200 sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, sample-01.txt
Case Name Status Exec Time Memory
01-01.txt 1 ms 256 KB
01-02.txt 1 ms 256 KB
01-03.txt 1 ms 256 KB
01-04.txt 1 ms 256 KB
01-05.txt 1 ms 256 KB
01-06.txt 1 ms 256 KB
01-07.txt 1 ms 256 KB
01-08.txt 1 ms 256 KB
01-09.txt 1 ms 256 KB
02-01.txt 1 ms 256 KB
02-02.txt 1 ms 256 KB
02-03.txt 1 ms 256 KB
02-04.txt 1 ms 256 KB
02-05.txt 1 ms 256 KB
02-06.txt 1 ms 256 KB
02-07.txt 1 ms 256 KB
02-08.txt 1 ms 256 KB
02-09.txt 1 ms 256 KB
sample-01.txt 1 ms 256 KB