QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#469950#8008. Fortune Wheelyz_lyWA 36ms5488kbC++141.7kb2024-07-10 09:12:322024-07-10 09:12:33

Judging History

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

  • [2024-07-30 15:38:33]
  • hack成功,自动添加数据
  • (/hack/759)
  • [2024-07-10 09:12:33]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:5488kb
  • [2024-07-10 09:12:32]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read(){
	int f=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			f=-f;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f*x;
}
inline void work(ll k){
	if(k<0){
		putchar('-');
		k=-k;
	}
	if(k>9)
		work(k/10);
	putchar(k%10+'0');
}
/*
首先预处理出0到每个点的最短路,按照最短路排序
首先发现操作一定是一开始使劲随机到一个最短路<=B,然后就开始走,考虑枚举这个阈值B
如果x本来就小于B就直接走,否则如果左边有i个期望n/i次随机到左边,期望步数就是n/i+sum[i]/i
*/
int n,x,k,a[505],dis[100005],id[100005],sum[100005],vis[100005];
queue<int> q;
bool cmp(int x,int y){
	return dis[x]<dis[y];
}
int main(){
	n=read();
	x=read();
	k=read();
	for(int i=1;i<=k;i++){
		a[i]=read();
	}
	for(int i=1;i<n;i++){
		dis[i]=1e9;
		id[i]=i;
	}
	q.emplace(0);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=1;i<=k;i++){
			if(dis[(u+a[i])%n]>dis[u]+1){
				dis[(u+a[i])%n]=dis[u]+1;
				q.emplace((u+a[i])%n);
			}
			if(dis[(u-a[i]+n)%n]>dis[u]+1){
				dis[(u-a[i]+n)%n]=dis[u]+1;
				q.emplace((u-a[i]+n)%n);
			}
		}
	}
	sort(id,id+n,cmp);
	sum[0]=dis[id[0]];
	for(int i=1;i<n;i++){
		sum[i]=sum[i-1]+dis[id[i]];
	}
	pair<ll,ll> mn=make_pair(1e18,1);
	for(int i=n-1;i>=0;i--){
		vis[id[i]]=1;
		if(dis[id[i]]==1e9)
			continue;
		if(!vis[x])
			mn=min(mn,make_pair((ll)dis[x],1ll));
		else{
			ll val=(i+1)*mn.first,val1=(n+sum[i])*mn.second;
			if(val>val1)
				mn=make_pair(n+sum[i],i+1);
		}
	}
	work(mn.first);
	putchar(' ');
	work(mn.second);
	return 0;
}

詳細信息

Test #1:

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

input:

6 3 2
2 4

output:

8 3

result:

ok 2 number(s): "8 3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

5 4 1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: 0
Accepted
time: 36ms
memory: 5488kb

input:

99999 65238 100
64714 45675 36156 13116 93455 22785 10977 60219 14981 25839 83709 80404 41400 12469 31530 65521 35436 20326 96792 50699 27522 98233 26187 12509 90992 72693 83919 74145 80892 68422 38333 33497 89154 88403 77492 4570 3908 59194 3482 89871 96330 45114 5555 73987 95832 476 949 74649 2084...

output:

3 1

result:

ok 2 number(s): "3 1"

Test #4:

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

input:

10000 23 7
9594 8998 9330 6851 1662 6719 583

output:

6 1

result:

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