답안 #21872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
21872 2017-04-26T14:49:39 Z petrpan 수열 (BOI14_sequence) C++14
100 / 100
263 ms 3004 KB
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> vii;

long long n;

long long back_track(vii a,int al=0)
{
	long long m=2e18;
	if (a.size()==1)
	{
		if (!a[0]) return 0;
		long long x=0;
		for (int i=1;i<=9;i++)
		{
			if (a[0]&(1<<i)) x*=10,x+=i;
			if (x and a[0]&1) x*=10,a[0]^=1;  
		}
		if (!x) x=1;
		if (a[0]&1) x*=10;
		return x;	
	}
	for (int i=0;i<=9-al;i++)
	{
		vii b(1,0);
		int cur=i,z=0;
		for (int j=0;j<a.size();j++)
		{
			if (cur==10) b.push_back(0),cur=0;
			int tp=a[j];
			if (a[j]&1 and cur==0) z=1;
			if (tp&(1<<cur)) tp^=1<<cur;
			b.back()|=tp;
			cur++;
		}
		long long tp=back_track(b,(a.size()<=2 and i==9))*10+i;
		if (!tp and z) tp=10; 
		m=min(m,tp);
	}	
	return m;
}

int main()
{
	//freopen("input.txt","r",stdin);
	cin >> n;
	vii x(0);
	for (int i=1;i<=n;i++)
	{
		int d;
		cin >> d;
		x.push_back(1<<d);
	}
	cout << back_track(x);
}

Compilation message

sequence.cpp: In function 'long long int back_track(vii, int)':
sequence.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0;j<a.size();j++)
                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Correct 0 ms 2020 KB Output is correct
6 Correct 0 ms 2020 KB Output is correct
7 Correct 0 ms 2020 KB Output is correct
8 Correct 0 ms 2020 KB Output is correct
9 Correct 0 ms 2020 KB Output is correct
10 Correct 0 ms 2020 KB Output is correct
11 Correct 0 ms 2020 KB Output is correct
12 Correct 0 ms 2020 KB Output is correct
13 Correct 0 ms 2020 KB Output is correct
14 Correct 0 ms 2020 KB Output is correct
15 Correct 3 ms 2020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Correct 0 ms 2020 KB Output is correct
6 Correct 0 ms 2020 KB Output is correct
7 Correct 0 ms 2020 KB Output is correct
8 Correct 0 ms 2020 KB Output is correct
9 Correct 3 ms 2020 KB Output is correct
10 Correct 0 ms 2020 KB Output is correct
11 Correct 0 ms 2020 KB Output is correct
12 Correct 0 ms 2020 KB Output is correct
13 Correct 0 ms 2020 KB Output is correct
14 Correct 0 ms 2020 KB Output is correct
15 Correct 0 ms 2020 KB Output is correct
16 Correct 0 ms 2020 KB Output is correct
17 Correct 3 ms 2020 KB Output is correct
18 Correct 0 ms 2020 KB Output is correct
19 Correct 0 ms 2020 KB Output is correct
20 Correct 0 ms 2020 KB Output is correct
21 Correct 0 ms 2020 KB Output is correct
22 Correct 3 ms 2020 KB Output is correct
23 Correct 0 ms 2020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 26 ms 2160 KB Output is correct
3 Correct 29 ms 2160 KB Output is correct
4 Correct 26 ms 2160 KB Output is correct
5 Correct 29 ms 2160 KB Output is correct
6 Correct 19 ms 2160 KB Output is correct
7 Correct 176 ms 2884 KB Output is correct
8 Correct 119 ms 2536 KB Output is correct
9 Correct 263 ms 3004 KB Output is correct
10 Correct 239 ms 3004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2020 KB Output is correct
2 Correct 0 ms 2020 KB Output is correct
3 Correct 0 ms 2020 KB Output is correct
4 Correct 0 ms 2020 KB Output is correct
5 Correct 146 ms 2528 KB Output is correct
6 Correct 0 ms 2020 KB Output is correct
7 Correct 0 ms 2020 KB Output is correct
8 Correct 3 ms 2020 KB Output is correct
9 Correct 0 ms 2020 KB Output is correct
10 Correct 3 ms 2020 KB Output is correct
11 Correct 253 ms 3004 KB Output is correct
12 Correct 233 ms 3004 KB Output is correct
13 Correct 0 ms 2020 KB Output is correct
14 Correct 0 ms 2020 KB Output is correct
15 Correct 0 ms 2020 KB Output is correct
16 Correct 0 ms 2020 KB Output is correct
17 Correct 0 ms 2020 KB Output is correct
18 Correct 0 ms 2020 KB Output is correct
19 Correct 0 ms 2020 KB Output is correct
20 Correct 0 ms 2020 KB Output is correct
21 Correct 0 ms 2020 KB Output is correct
22 Correct 0 ms 2020 KB Output is correct
23 Correct 0 ms 2020 KB Output is correct
24 Correct 0 ms 2020 KB Output is correct
25 Correct 3 ms 2020 KB Output is correct
26 Correct 3 ms 2020 KB Output is correct
27 Correct 26 ms 2160 KB Output is correct
28 Correct 26 ms 2160 KB Output is correct
29 Correct 26 ms 2160 KB Output is correct
30 Correct 26 ms 2160 KB Output is correct
31 Correct 23 ms 2160 KB Output is correct
32 Correct 176 ms 2884 KB Output is correct
33 Correct 143 ms 2536 KB Output is correct
34 Correct 263 ms 3004 KB Output is correct
35 Correct 236 ms 3004 KB Output is correct
36 Correct 179 ms 2896 KB Output is correct
37 Correct 239 ms 2996 KB Output is correct
38 Correct 146 ms 2580 KB Output is correct
39 Correct 246 ms 3004 KB Output is correct
40 Correct 263 ms 3004 KB Output is correct