QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#467257#8008. Fortune WheelInclude_Z_F_R_WA 0ms3784kbC++141.5kb2024-07-08 15:25:592024-07-08 15:25:59

Judging History

你现在查看的是最新测评结果

  • [2024-07-30 15:38:33]
  • hack成功,自动添加数据
  • (/hack/759)
  • [2024-07-10 08:02:33]
  • hack成功,自动添加数据
  • (/hack/730)
  • [2024-07-08 15:25:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2024-07-08 15:25:59]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll Read() {
	int sig = 1;
	ll num = 0;
	char c = getchar();
	while(!isdigit(c)) {
		if(c == '-') {
			sig = -1;
		}
		c = getchar();
	}
	while(isdigit(c)) {
		num = (num << 3) + (num << 1) + (c ^ 48);
		c = getchar();
	}
	return num * sig;
}
void Write(ll x) {
	if(x < 0) {
		putchar('-');
		x = -x;
	}
	if(x >= 10) {
		Write(x / 10);
	}
	putchar((x % 10) ^ 48);
}

const int N = 100005, K = 505;
int n, x, k, p[K], dis[N];
const int inf = 1e9;
bool vis[N];
struct tNode {
	int u;
	ll dis;
	friend bool operator <(tNode x, tNode y) {
		return x.dis > y.dis;
	}
};
void Bfs() {
	int i;
	queue<int> q; 
	for(i = 1; i < n; i++) {
		dis[i] = inf;
	}
	dis[0] = 0;
	q.push(0);
	vis[0] = true;
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(i = 1; i <= k; i++) {
			int v = (u - p[i] + n) % n;
			ll d = dis[u] + 1;
			if(!vis[v]) {
				dis[v] = d;
				vis[v] = true;
				q.push(v);
			}
		}
	}
}

int main() {
	n = Read(), x = Read(), k = Read();
	int i;
	for(i = 1; i <= k; i++) {
		p[i] = Read();
	}
	Bfs();
//	for(i = 0; i < n; i++) {
//		cout << dis[i] << ' ';
//	}
//	cout << endl;
	ll xd = dis[x];
	sort(dis, dis + n);
	double ans = double(xd);
	ll p, q, s = dis[0];
	for(i = 1; i <= n && dis[i] <= xd; i++) {
		if(ans > (n + s) * 1.0 / i) {
			ans = (n + s) * 1.0 / i, p = n + s, q = i;
		}
		s += dis[i];
	}
	ll g = __gcd(p, q);
	Write(p / g), putchar(' '), Write(q / g);
	return 0;
}
/*
  
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

input:

6 3 2
2 4

output:

8 3

result:

ok 2 number(s): "8 3"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3608kb

input:

5 4 1
1

output:

0 1

result:

wrong answer 1st numbers differ - expected: '1', found: '0'