Submission #421450

# Submission time Handle Problem Language Result Execution time Memory
421450 2021-06-09T07:34:15 Z Nicholas_Patrick Sequence (BOI14_sequence) C++17
25 / 100
75 ms 716 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);
				reduced|=x!=masks[j*10+i];
				newMasks[j+additional]|=x;
			}
		}
		while(not newMasks.empty() and newMasks.back()==0)
			newMasks.pop_back();
		if(not reduced and newMasks.size()==masks.size())
			continue;
		ret=min(ret, solve(newMasks, depth+1, fu==0)*10+fu);
	}
	if(ret==0)
		ret=positive;
	return ret;
}
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));
	// printf("%.3lf\n", (double)clock()/CLOCKS_PER_SEC);
}

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:62:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  scanf("%d", &k);
      |  ~~~~~^~~~~~~~~~
sequence.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   scanf("%d", &i), i=1<<i;
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 14 ms 204 KB Output is correct
3 Correct 14 ms 328 KB Output is correct
4 Correct 8 ms 324 KB Output is correct
5 Correct 8 ms 332 KB Output is correct
6 Correct 6 ms 204 KB Output is correct
7 Correct 54 ms 564 KB Output is correct
8 Correct 54 ms 460 KB Output is correct
9 Correct 74 ms 716 KB Output is correct
10 Correct 75 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -