QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#731#470292#8008. Fortune WheelxiahaobZ_drjFailed.2024-07-10 16:14:592024-07-10 16:14:59

Details

Extra Test:

Invalid Input

input:

1

output:


result:

FAIL Unexpected character #10, but ' ' expected (stdin, line 1)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#470292#8008. Fortune WheelZ_drjAC ✓86ms4540kbC++14948b2024-07-10 11:48:272024-07-30 15:41:13

answer

#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>

using i64 = long long;

const int N = 1e5 + 5;

int n, x, k;
int a[N], dis[N];

void bfs(int s){
	memset(dis + 1, 0x3f, sizeof(int) * (n));
	std::queue<int> q;
	q.push(s);

	while (!q.empty()) {
		int u = q.front(); q.pop();
		
		for (int i = 1; i <= k; i++) {
			int v = (u - a[i] + n) % n;
			if (dis[v] == 0x3f3f3f3f) {
				dis[v] = dis[u] + 1;
				q.push(v);
			}
		}
	}
}

int main(){
	scanf("%d %d %d", &n, &x, &k);

	for (int i = 1; i <= k; i++) {
		scanf("%d", a + i);
	}

	bfs(0);
	i64 p = dis[x], q = 1;
	std::sort(dis + 1, dis + n + 1);

	i64 sum = 0;
	for (int i = 0; i < n; i++) {
		if (dis[i] == 0x3f3f3f3f) {
			break;
		}
		sum += dis[i];
		i64 np = n + sum, nq = i + 1;
		if (q * np < p * nq) {
			p = np, q = nq;
		}
	}

	i64 g = std::__gcd(p, q);
	printf("%lld %lld\n", p / g, q / g);
	return 0;
}