QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#471404#8008. Fortune WheelkoukileeWA 2ms5612kbC++232.2kb2024-07-10 20:57:162024-07-10 20:57:16

Judging History

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

  • [2024-07-30 15:38:33]
  • hack成功,自动添加数据
  • (/hack/759)
  • [2024-07-10 20:57:16]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5612kb
  • [2024-07-10 20:57:16]
  • 提交

answer

/* The code is from koukilee*/
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using i32 = int; using i64 = long long; // std::mt19937 rd(time(0));
constexpr i64 MAXN = 1010100, mod = 1e9 + 7, INF = 992009100720100812; 

//char buf[1 << 21], *p1 = buf, *p2 = buf, obuf[1 << 21], *O=obuf;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) 
inline void read (i64 &sum) noexcept {
    i64 tf = 0; char ch = getchar(); sum = 0;
    while (ch < '0' || ch > '9') tf = ch == '-' ? 1 : 0, ch = getchar();
    while (ch >= '0' && ch <= '9') sum = (sum << 1) + (sum << 3) + (ch ^ 48), ch = getchar();
    (tf) && (sum =- sum);
}template <typename i64,typename ...Args>
inline void read (i64 &tmp, Args &...tmps) noexcept{read(tmp); read(tmps...);}
void printt (i64 x) noexcept {if(x >= 10) printt(x / 10); putchar(x % 10 + '0');} 
inline void print (i64 x) noexcept{x < 0 ? putchar('-'), printt(-x) : printt(x);}
inline void put (i64 x) noexcept{print(x), putchar('\n');}

inline i64 min(i64 a, i64 b) noexcept{return a > b ? a : b;}

struct node{
	i64 id, val;
	
	bool operator < (const node& nex) const{
		return val > nex.val;
	}
};

i64 n, x, k, dis[MAXN]; std::vector<i64>g[MAXN];
std::priority_queue<node>p;

inline void dijkstra() noexcept{
	for (i32 i = 0; i <= n; i++)
		dis[i] = INF;
	
	p.push((node){0, 0}), dis[0] = 0;
	while (!p.empty()){
		node nex = p.top(); p.pop(); if (nex.val != dis[nex.id]) continue;
		
		for (auto it : g[nex.id]){
			if (dis[nex.id] + 1 < dis[it]){
				dis[it] = dis[nex.id] + 1;
				p.push((node){it, dis[it]});
			}
		}
	}
}

i64 gcd(i64 a, i64 b) noexcept{return b ? gcd(b, a % b) : a;}

int main() noexcept{
	read(n, x, k);
	
	for (i64 i = 1, p; i <= k; i++){
		read(p);
		for (i32 j = 0; j < n; j++)
			g[(j + p) % n].push_back(j);
	}
	
	dijkstra();
	
	i64 a = min(dis[x], n), b = 1, l = 0, sum = 0;
	
	std::sort(dis, dis + n);
	
	for (i32 i = 0; i <= n; i++){
		while (l < n && dis[l] <= i) sum += dis[l++];
		
		i64 p = n + sum, q = l;
		if (p * b < a * q) a = p, b = q;
	}
	
	print(a / gcd(a, b)), putchar(' '), print(b / gcd(a, b));
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5612kb

input:

6 3 2
2 4

output:

8 3

result:

ok 2 number(s): "8 3"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 5544kb

input:

5 4 1
1

output:

8 3

result:

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