Submission #3777660


Source Code Expand

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,0,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define d(a) if(isDebugMode) cout<<#a<<"="<<a<<","
#define d2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b
#define d3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c
#define d4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d
#define da(arr,N){if(isDebugMode){rep(i,N){if(arr[i]==INF)printf("INF ");else cout<<arr[i]<<" ";} cout<<endl;}}
#define da2(arr,N,M){if(isDebugMode)rep(i,N){rep(j,M){if(arr[i][j]==INF)printf(" INF");else printf(" %3d",arr[i][j]);}cout<<endl;}}
#define pb push_back
#define pob pop_back

auto chmax = [](int &a, int b) { a = max(a, b); };
auto chmin = [](int &a, int b) { a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[4] = { 0, 1, 0,-1 };
const int dy[4] = { 1, 0,-1, 0 };

bool isDebugMode = 1;
//--------------------------------------//
ll n;
ll x;

void swap(ll &a, ll &b) {
	ll tmp = a;
	a = b;
	b = tmp;
}

ll f(ll a, ll b) {
	if (a == b)
		return a;
	if (a > b)
		swap(a, b);
	return 2 * a + f(b - a, a);
}

void solve() {
	cout << n + f(n - x, x) << endl;
}

int main() {
	cin >> n >> x;
	solve();
	return 0;
}

Submission Info

Submission Time
Task B - Mysterious Light
User J190755SW
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1618 Byte
Status TLE
Exec Time 2103 ms
Memory 256 KB

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 300 / 300 0 / 200
Status
AC × 1
AC × 10
AC × 17
TLE × 3
Set Name Test Cases
Sample sample-01.txt
Subtask 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 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 AC 1 ms 256 KB
01-02.txt AC 1 ms 256 KB
01-03.txt AC 1 ms 256 KB
01-04.txt AC 1 ms 256 KB
01-05.txt AC 1 ms 256 KB
01-06.txt AC 1 ms 256 KB
01-07.txt AC 1 ms 256 KB
01-08.txt AC 1 ms 256 KB
01-09.txt AC 1 ms 256 KB
02-01.txt TLE 2103 ms 256 KB
02-02.txt TLE 2103 ms 256 KB
02-03.txt AC 1 ms 256 KB
02-04.txt AC 1 ms 256 KB
02-05.txt AC 1 ms 256 KB
02-06.txt AC 1 ms 256 KB
02-07.txt AC 1 ms 256 KB
02-08.txt AC 2 ms 256 KB
02-09.txt TLE 2103 ms 256 KB
sample-01.txt AC 1 ms 256 KB