0 pts 全WA求调
查看原帖
0 pts 全WA求调
1285691
yinbe2楼主2024/10/1 13:46
#include<iostream>
#include<map>
#define int long long
using namespace std;
int n;
long long k,x,sum,cnt,a[200005],oth,cnt_oth;
map<long long,long long>mp;
map<long long,bool>xunhuan;
signed main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	while(1)
	{
		if(mp.find(a[x%n])!=mp.end())
		{
			break;
		}
		mp[a[x%n]]=cnt;
		x+=a[x%n];
		cnt++;
	}
	if(cnt>k)
	{
		for(int i=1;i<=k;i++)
		{
			sum+=a[sum%n];
		}	
		printf("%lld",sum);
		return 0;	
	}
	for(auto it:mp)
	{
		if(it.second>=mp[a[x%n]])
		{
			xunhuan[it.first]=true;
		}
		else
		{
			oth+=it.first;
			cnt_oth++;
		}
	}
	cnt=xunhuan.size();
	k-=cnt_oth;
	for(auto it:xunhuan)
	{
		sum+=it.first;
	}
	sum*=(k/cnt);
	sum+=oth;
	for(int i=1;i<=k%cnt;i++)
	{
		sum+=a[sum%n];
	}
	printf("%lld",sum);
	return 0;
}
```
2024/10/1 13:46
加载中...