답안 #421587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421587 2021-06-09T09:43:10 Z Nicholas_Patrick 수열 (BOI14_sequence) C++17
100 / 100
575 ms 884 KB
#pragma GCC optimize("O3")
#include <cstdio>
#include <queue>
#include <random>
using namespace std;

int singleLookup[1024];
int single(int mask){
	long long ret=0, mult=1;
	if(mask==1)
		return 10;
	for(int i=10; --i;){
		if(mask>>i&1){
			ret+=mult*i;
			mult*=10;
		}
	}
	if(mask&1){
		mult/=10;
		ret+=ret/mult*mult*9;
	}
	return ret;
}
long long solve(vector<int>& masks, int depth=0, bool positive=true){
	if(depth>=15)
		return 1;
	if(masks.size()==0)
		return positive;
	if(masks.size()==1){
		int ret=singleLookup[masks[0]];
		return ret?ret:positive;
	}
	long long ret=102345678888889;
	for(int fu=0; fu<10; fu++){
		vector<int> newMasks((masks.size()-1+fu)/10+1, 0);
		bool reduced=false;
		for(int i=0; i<10; i++){
			int u=fu+i;
			bool additional=u>=10;
			if(additional)
				u-=10;
			for(int j=0; j*10+i<masks.size(); j++){
				int x=masks[j*10+i]&~(1<<u);
				if(x!=masks[j*10+i] and i==0)
					reduced=true;
				newMasks[j+additional]|=x;
			}
		}
		while(not newMasks.empty() and newMasks.back()==0)
			newMasks.pop_back();
		ret=min(ret, solve(newMasks, depth+1, fu==0 and reduced)*10+fu);
	}
	return ret?ret:positive;
}
int main(){
	for(int i=0; i<1024; i++)
		singleLookup[i]=single(i);
	int k;
	scanf("%d", &k);
	vector<int> b(k);
	for(int& i : b)
		scanf("%d", &i), i=1<<i;
	printf("%lld\n", solve(b));
}

Compilation message

sequence.cpp: In function 'long long int solve(std::vector<int>&, int, bool)':
sequence.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |    for(int j=0; j*10+i<masks.size(); j++){
      |                 ~~~~~~^~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  scanf("%d", &k);
      |  ~~~~~^~~~~~~~~~
sequence.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |   scanf("%d", &i), i=1<<i;
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 288 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
11 Correct 5 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 3 ms 204 KB Output is correct
14 Correct 6 ms 204 KB Output is correct
15 Correct 7 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 4 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 11 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 6 ms 204 KB Output is correct
10 Correct 1 ms 280 KB Output is correct
11 Correct 5 ms 276 KB Output is correct
12 Correct 5 ms 204 KB Output is correct
13 Correct 8 ms 284 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 7 ms 204 KB Output is correct
17 Correct 9 ms 292 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 2 ms 280 KB Output is correct
20 Correct 6 ms 204 KB Output is correct
21 Correct 3 ms 204 KB Output is correct
22 Correct 10 ms 284 KB Output is correct
23 Correct 9 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 67 ms 204 KB Output is correct
3 Correct 67 ms 308 KB Output is correct
4 Correct 10 ms 204 KB Output is correct
5 Correct 9 ms 332 KB Output is correct
6 Correct 45 ms 312 KB Output is correct
7 Correct 367 ms 588 KB Output is correct
8 Correct 255 ms 472 KB Output is correct
9 Correct 561 ms 684 KB Output is correct
10 Correct 528 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 279 ms 460 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 7 ms 284 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 11 ms 288 KB Output is correct
11 Correct 575 ms 796 KB Output is correct
12 Correct 551 ms 844 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 5 ms 204 KB Output is correct
15 Correct 6 ms 204 KB Output is correct
16 Correct 7 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 7 ms 204 KB Output is correct
20 Correct 10 ms 288 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 3 ms 204 KB Output is correct
23 Correct 8 ms 284 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 9 ms 204 KB Output is correct
26 Correct 6 ms 288 KB Output is correct
27 Correct 64 ms 336 KB Output is correct
28 Correct 76 ms 332 KB Output is correct
29 Correct 8 ms 332 KB Output is correct
30 Correct 9 ms 348 KB Output is correct
31 Correct 54 ms 308 KB Output is correct
32 Correct 361 ms 716 KB Output is correct
33 Correct 396 ms 552 KB Output is correct
34 Correct 568 ms 872 KB Output is correct
35 Correct 565 ms 884 KB Output is correct
36 Correct 395 ms 716 KB Output is correct
37 Correct 535 ms 844 KB Output is correct
38 Correct 319 ms 632 KB Output is correct
39 Correct 553 ms 880 KB Output is correct
40 Correct 557 ms 880 KB Output is correct