답안 #421802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421802 2021-06-09T12:21:07 Z Pyqe 수열 (BOI14_sequence) C++14
100 / 100
139 ms 1376 KB
#include <bits/stdc++.h>

using namespace std;

const long long inf=1e18;
long long nn[8],p10[60],z=inf;
bitset<11> fq[8][100069],tmp;

void rk(long long x,long long cw,bool bad)
{
	if(nn[x]>1)
	{
		long long i,j;
		
		for(i=0;i<10-bad;i++)
		{
			nn[x+1]=(nn[x]+i-1)/10+1;
			for(j=0;j<nn[x+1];j++)
			{
				fq[x+1][j].reset();
			}
			for(j=0;j<nn[x];j++)
			{
				tmp=fq[x][j];
				if((i+j)%10==0)
				{
					tmp[10]=tmp[10]||tmp[0];
				}
				tmp[(i+j)%10]=0;
				if((i+j)%10)
				{
					tmp[10]=0;
				}
				fq[x+1][(i+j)/10]|=tmp;
			}
			rk(x+1,cw+i*p10[x],nn[x+1]==nn[x]);
		}
	}
	else
	{
		long long i,l=0,p=x;
		
		for(i=9;i;i--)
		{
			if(fq[x][0][i])
			{
				cw+=i*p10[p];
				p++;
				l=i;
			}
		}
		if(fq[x][0][0])
		{
			cw+=l*(p10[p]-p10[p-1]);
			p++;
		}
		if((fq[x][0][0]||fq[x][0][10])&&!l)
		{
			cw+=p10[p];
		}
		z=min(z,cw);
	}
}

int main()
{
	long long i,k;
	
	p10[0]=1;
	for(i=1;i<60;i++)
	{
		p10[i]=p10[i-1]*10;
	}
	scanf("%lld",nn);
	for(i=0;i<nn[0];i++)
	{
		scanf("%lld",&k);
		fq[0][i][k]=1;
	}
	rk(0,0,0);
	printf("%lld\n",z);
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |  scanf("%lld",nn);
      |  ~~~~~^~~~~~~~~~~
sequence.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |   scanf("%lld",&k);
      |   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 11 ms 332 KB Output is correct
3 Correct 11 ms 428 KB Output is correct
4 Correct 12 ms 432 KB Output is correct
5 Correct 12 ms 332 KB Output is correct
6 Correct 9 ms 332 KB Output is correct
7 Correct 68 ms 844 KB Output is correct
8 Correct 46 ms 716 KB Output is correct
9 Correct 95 ms 1176 KB Output is correct
10 Correct 97 ms 1184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 45 ms 716 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 96 ms 1180 KB Output is correct
12 Correct 109 ms 1372 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 11 ms 460 KB Output is correct
28 Correct 11 ms 456 KB Output is correct
29 Correct 12 ms 460 KB Output is correct
30 Correct 13 ms 460 KB Output is correct
31 Correct 8 ms 420 KB Output is correct
32 Correct 72 ms 1052 KB Output is correct
33 Correct 54 ms 800 KB Output is correct
34 Correct 93 ms 1348 KB Output is correct
35 Correct 93 ms 1356 KB Output is correct
36 Correct 73 ms 1076 KB Output is correct
37 Correct 93 ms 1360 KB Output is correct
38 Correct 56 ms 920 KB Output is correct
39 Correct 100 ms 1376 KB Output is correct
40 Correct 139 ms 1292 KB Output is correct