UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#194721#2352. Hoptkswls10027ms2820kbC++111.7kb2023-10-17 11:22:102023-10-17 12:04:20

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, x, y, z, p, k, ans, vis[100005];
long long a, b, xx, yy, tx, q, op, opp, aa, bb, aaa, bbb, f[100005];
struct node {
	int name, num;
	bool operator < (const node& p)const {
		return num > p.num;
	}
};
priority_queue<node> que;
inline void dijkstra() {
	memset(f, 0x3f, sizeof(f));
	f[0] = 0;
	que.push(node{0, 0});
	node u;
	while (que.size()) {
		u = que.top();
		que.pop();
		if (vis[u.name]) continue;
		vis[u.name] = 1;
		if (!vis[(u.name + x) % z] && f[(u.name + x) % z] > u.num + x) {
			f[(u.name + x) % z] = u.num + x;
			que.push(node{(u.name + x) % z, f[(u.name + x) % z]});
		}
		if (!vis[(u.name + y) % z] && f[(u.name + y) % z] > u.num + y) {
			f[(u.name + y) % z] = u.num + y;
			que.push(node{(u.name + y) % z, f[(u.name + y) % z]});
		}
	}
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> x >> y >> z;
	n--;
	if (__gcd(__gcd(x, y), z) != 1) {
		p = __gcd(__gcd(x, y), z);
		x /= p, y /= p, z /= p, n /= p;
	}
	if (x > y) swap(x, y);
	if (x > z) swap(x, z);
	if (y > z) swap(y, z);
	if (__gcd(x, y) == 1) {
	} else if (__gcd(x, z) == 1) {
		swap(y, z);
	} else {
		swap(x, z);
	}
	k = x * y - x - y, p = z / __gcd(x, z), q = z / __gcd(y, z), op = x / __gcd(x, y), opp = y / __gcd(x, y);
	ans += max(0ll, n - max(k, 0ll));
	if (k <= 0) {
		cout << ans + 1;
		return 0;
	}
	dijkstra();
	k = min(k, n);
	for (int i = 0; i < z; i++) {
		if (i == 0) {
			ans += max(0ll, k / z);
			continue;
		}
		if (i <= k % z) {
			ans += max(0ll, (k / z - f[i] / z) + 1);
		} else {
			ans += max(0ll, (k / z - f[i] / z));
		}
	}
	cout << ans + 1;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

100
1 1 2

output:

100

result:

ok 1 number(s): "100"

Test #2:

score: 10
Accepted
time: 1ms
memory: 2048kb

input:

18
5 2 3

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: 10
Accepted
time: 1ms
memory: 2048kb

input:

54000
78 114 80000

output:

8892

result:

ok 1 number(s): "8892"

Test #4:

score: 10
Accepted
time: 8ms
memory: 2812kb

input:

65432
98765 87654 76543

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 10
Accepted
time: 8ms
memory: 2720kb

input:

1000000000000000000
98868 86420 90035

output:

999999999959377161

result:

ok 1 number(s): "999999999959377161"

Test #6:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

271828182845904523
64000 16000 32000

output:

16989261427870

result:

ok 1 number(s): "16989261427870"

Test #7:

score: 10
Accepted
time: 5ms
memory: 2820kb

input:

987654321987654321
99995 99997 99999

output:

987654319487854318

result:

ok 1 number(s): "987654319487854318"

Test #8:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

314159265358979323
478 239 717

output:

1314473913635897

result:

ok 1 number(s): "1314473913635897"

Test #9:

score: 10
Accepted
time: 2ms
memory: 2124kb

input:

1000000000000000000
60984 87654 76656

output:

166666666664422831

result:

ok 1 number(s): "166666666664422831"

Test #10:

score: 10
Accepted
time: 2ms
memory: 2116kb

input:

1000000000000000000
99396 99495 99880

output:

90909090907974180

result:

ok 1 number(s): "90909090907974180"

Extra Test:

score: 0
Extra Test Passed