QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#303564#6300. Best Carry Player 2ucup-team052#WA 0ms3772kbC++231.6kb2024-01-12 18:48:012024-01-12 18:48:02

Judging History

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

  • [2024-01-12 18:48:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3772kb
  • [2024-01-12 18:48:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define int unsigned long long
#define inf 0x3f3f3f3f
#define INF ((int)1e19)
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
int pw[105];
int f[2][19],g[2][19];
void work()
{
	int n=read(),k=read();
	vector<int> s;
	while(n)
	{
		s.push_back(n%10);
		n/=10;
	}
	while((int)s.size()<k+1) s.push_back(0);
	if(k==0)
	{
		int pw=1;
		for(int i=0;;i++)
		{
			if(s[i]!=9)
			{
				printf("%lld\n",(long long)pw);
				return ;
			}
			pw*=10;
		}
	}
	for(int i=1;i<=18;i++) f[0][i]=f[1][i]=INF;
	f[0][0]=0,f[1][0]=INF;
	for(int i=0;i<(int)s.size();i++)
	{
		// if(s[i]==9)
		{
			int j=i;
			while(s[j+1]==9) j++;
			int l=j-i+1;
			for(int i=0;i<=18;i++) g[0][i]=g[1][i]=INF;
			for(int c=0;c<=k;c++) for(int o=0;o<2;o++)
			{
				for(int d=1;d<=l&&c+d<=k;d++)
				{
					int w=10-s[j-d+1];
					if(d==l&&o) w--;
					if(w<=9) g[1][c+d]=min(g[1][c+d],f[o][c]+pw[j-d+1]*w);
				}
				g[0][c]=min(g[0][c],f[o][c]);
			}
			memcpy(f,g,sizeof(f));
			i=j;
		}
	}
	printf("%llu\n",min(f[1][k],f[0][k]));
}
signed main()
{
	pw[0]=1; for(int i=1;i<=19;i++) pw[i]=pw[i-1]*10;
	int T=read(); while(T--) work();
	return 0;
}



詳細信息

Test #1:

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

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9910

result:

ok 4 lines

Test #2:

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

input:

21
999990000099999 0
999990000099999 1
999990000099999 2
999990000099999 3
999990000099999 4
999990000099999 5
999990000099999 6
999990000099999 7
999990000099999 8
999990000099999 9
999990000099999 10
999990000099999 11
999990000099999 12
999990000099999 13
999990000099999 14
999990000099999 15
999...

output:

100000
10000
1000
100
10
1
900001
9900001
99900001
999900001
10000000001
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
553255926290448384
1000000000000000000

result:

wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '553255926290448384'