提交记录 7002


用户 题目 状态 得分 用时 内存 语言 代码长度
Snakes noip18b. 【NOIP2018】货币系统 Accepted 100 33.967 ms 28 KB C++ 1017 B
提交时间 评测时间
2018-12-08 16:47:28 2020-08-01 00:56:55
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=105;
const int M=25005;
int t;
int n;
int a[N];
int d[M],mv;
int dv,dx,dj;
int ans;
int gcd(int a,int b)
{
	if (a%b==0)
		return b;
	return gcd(b,a%b);
}
int main()
{
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d",&n);
		for (int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		mv=a[1];
		for (int i=1;i<mv;i++)
			d[i]=-1;
		d[0]=0;
		ans=1;
		for (int i=2;i<=n;i++)
		{
			dv=a[i]/mv;
			dx=a[i]%mv;
			if (d[dx]<=dv&&d[dx]!=-1)
				continue;
			ans++;
			if (dx==0)
				dj=mv;
			else
				dj=gcd(dx,mv);
			for (int j=0;j<dj;j++)
			{
				int k=j;
				do
				{
					int nx=(k+dx)%mv;
					if (d[k]!=-1)
						if (d[nx]==-1||d[k]+dv+(k+dx>=mv)<d[nx])
							d[nx]=d[k]+dv+(k+dx>=mv);
					k=nx;
				}
				while (k!=j);
				do
				{
					int nx=(k+dx)%mv;
					if (d[k]!=-1)
						if (d[nx]==-1||d[k]+dv+(k+dx>=mv)<d[nx])
							d[nx]=d[k]+dv+(k+dx>=mv);
					k=nx;
				}
				while (k!=j);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #195.45 us20 KBAcceptedScore: 5

Testcase #2111.6 us24 KBAcceptedScore: 5

Testcase #384.67 us20 KBAcceptedScore: 5

Testcase #4137.86 us20 KBAcceptedScore: 5

Testcase #5140.52 us20 KBAcceptedScore: 5

Testcase #6154.34 us20 KBAcceptedScore: 5

Testcase #7180.83 us20 KBAcceptedScore: 5

Testcase #8173.37 us20 KBAcceptedScore: 5

Testcase #9197.42 us20 KBAcceptedScore: 5

Testcase #10147.46 us20 KBAcceptedScore: 5

Testcase #1138.86 us20 KBAcceptedScore: 5

Testcase #1238.18 us20 KBAcceptedScore: 5

Testcase #1335.44 us20 KBAcceptedScore: 5

Testcase #1475.59 us20 KBAcceptedScore: 5

Testcase #1575.06 us20 KBAcceptedScore: 5

Testcase #1676.33 us20 KBAcceptedScore: 5

Testcase #1733.967 ms28 KBAcceptedScore: 5

Testcase #1830.966 ms28 KBAcceptedScore: 5

Testcase #1929.153 ms28 KBAcceptedScore: 5

Testcase #2029.38 ms28 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:36:55 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠