185342025-10-26 11:42:39ubormaciJárdakövezéscpp17Time limit exceeded 0/751.1s508 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
// #pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

std::lcm(ll a, ll b), std::gcd(int a, int b)

cout << fixed << setprecision(n);

set with custom ordering
set<ll, decltype(&cmp)> qu(cmp);

*/

typedef int64_t ll;

ll extendedeuclid(ll a, ll b, ll &x, ll &y) {

	if(b == 0) {
		x = 1;
		y = 0;
		return a;
	}

	ll x1, y1;
	ll d = extendedeuclid(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}	

void solve() {

	ll h, a, b;
	cin >> h >> a >> b;

	// a * x + b * y = c
	// oldest problem in the book
	// and I'm still shit at it but let's not get so hasty

	// szoval
	// standard extended euclidean algorithm megoldja a * x + b * y = gcd(x, y)
	// es erre ad egy a, b erteket
	// ha c mod gcd = 0, akkor egyszeruen vesszik c / g es beszorozzuk vele az x/y-t

	ll g = gcd(a, b);
	if(h % g != 0) {
		cout << "0 0";
		return;
	}

	ll x0, y0;
	extendedeuclid(a, b, x0, y0);
	x0 *= h / g;
	y0 *= h / g;

	ll k = 0;
	while(1) {

		ll x = x0 + k * (b/g);
		ll y = y0 - k * (a/g);

		if(x >= 0 && y >= 0) {
			cout << x << " " << y;
			return;
		}
		k++;
	}
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);

	solve();

	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask20/12
2Time limit exceeded1.09s316 KiB
3Accepted1ms316 KiB
4Accepted1ms316 KiB
5Accepted1ms508 KiB
6Accepted1ms316 KiB
7Accepted1ms508 KiB
8Accepted1ms320 KiB
9Accepted1ms316 KiB
10Time limit exceeded1.1s316 KiB
11Accepted1ms316 KiB
12Time limit exceeded1.1s316 KiB
13Time limit exceeded1.1s316 KiB
subtask30/12
14Time limit exceeded1.082s500 KiB
15Accepted4ms508 KiB
16Time limit exceeded1.082s316 KiB
17Accepted1ms496 KiB
18Accepted1ms500 KiB
19Time limit exceeded1.098s316 KiB
20Accepted1ms424 KiB
21Time limit exceeded1.1s316 KiB
22Accepted1ms316 KiB
23Accepted1ms316 KiB
24Time limit exceeded1.098s316 KiB
25Accepted1ms316 KiB
subtask40/24
26Time limit exceeded1.082s500 KiB
27Accepted1ms316 KiB
28Accepted1ms316 KiB
29Time limit exceeded1.082s316 KiB
30Accepted1ms316 KiB
31Accepted1ms316 KiB
32Time limit exceeded1.1s316 KiB
33Time limit exceeded1.1s316 KiB
34Time limit exceeded1.08s316 KiB
35Time limit exceeded1.082s316 KiB
36Accepted1ms316 KiB
37Time limit exceeded1.09s508 KiB
38Time limit exceeded1.098s316 KiB
39Time limit exceeded1.088s500 KiB
40Time limit exceeded1.088s316 KiB
41Time limit exceeded1.1s316 KiB
42Time limit exceeded1.082s316 KiB
43Accepted1ms316 KiB
44Accepted1ms508 KiB
45Accepted1ms316 KiB
46Time limit exceeded1.1s316 KiB
47Accepted1ms316 KiB
48Accepted1ms316 KiB
49Accepted1ms316 KiB
subtask50/27
50Time limit exceeded1.075s316 KiB
51Accepted1ms508 KiB
52Accepted1ms316 KiB
53Accepted2ms316 KiB
54Time limit exceeded1.1s316 KiB
55Accepted2ms316 KiB
56Accepted3ms316 KiB
57Time limit exceeded1.1s316 KiB
58Time limit exceeded1.1s316 KiB
59Accepted2ms316 KiB
60Accepted1ms316 KiB
61Accepted2ms316 KiB
62Accepted2ms316 KiB
63Accepted2ms416 KiB
64Accepted1ms508 KiB
65Accepted3ms316 KiB
66Time limit exceeded1.1s316 KiB
67Time limit exceeded1.1s316 KiB
68Time limit exceeded1.1s316 KiB
69Time limit exceeded1.1s316 KiB
70Time limit exceeded1.07s316 KiB
71Time limit exceeded1.1s508 KiB
72Accepted1ms316 KiB
73Accepted4ms316 KiB
74Accepted1ms316 KiB
75Accepted1ms316 KiB
76Accepted1ms316 KiB