답안 #465515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465515 2021-08-16T09:14:17 Z prvocislo 수열 (BOI14_sequence) C++17
100 / 100
207 ms 1092 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
typedef long long ll;
using namespace std;

ll solve(const vector<int>& v, bool not9)
{
	if (v.size() == 1)
	{
		ll ans = 0;
		for (int i = 1; i <= 9; i++) if (v[0] & (1 << i))
		{
			ans = ans * 10 + i;
			if (ans == i && (v[0] & 1)) ans *= 10;
		}
		if (!ans && (v[0] & 1)) ans = 10;
		return ans;
	}
	else
	{
		ll ans = 1e16;
		for (int last = 0; last <= 9 - (int)not9; last++)
		{
			vector<int> v2;
			int mask = 0;
			bool zero = false;
			for (int i = 0, j = last; i < v.size(); i++, j = (j + 1) % 10)
			{
				int my = v[i];
				if (my & (1 << j)) my ^= (1 << j);
				mask |= my;
				if (!j && (v[i] & 1)) zero = true;
				if (j == 9 || i + 1 == v.size())
				{
					v2.push_back(mask);
					mask = 0;
				}
			}
			ll num = solve(v2, (v.size() == 2 && last == 9)) * 10 + last;
			if (!num && zero) num = 10; // potrebujeme mat nieco na zaciatku, aby nam neodisla ta 0
			ans = min(ans, num);
		}
		return ans;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k;
	cin >> k;
	vector<int> v(k);
	for (int i = 0; i < k; i++) cin >> v[i], v[i] = (1 << v[i]);
	cout << solve(v, false) << "\n";
	return 0;
}

Compilation message

sequence.cpp: In function 'll solve(const std::vector<int>&, bool)':
sequence.cpp:29:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |    for (int i = 0, j = last; i < v.size(); i++, j = (j + 1) % 10)
      |                              ~~^~~~~~~~~~
sequence.cpp:35:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if (j == 9 || i + 1 == v.size())
      |                   ~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 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 2 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 312 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 21 ms 332 KB Output is correct
3 Correct 19 ms 332 KB Output is correct
4 Correct 19 ms 396 KB Output is correct
5 Correct 22 ms 396 KB Output is correct
6 Correct 16 ms 364 KB Output is correct
7 Correct 119 ms 716 KB Output is correct
8 Correct 81 ms 588 KB Output is correct
9 Correct 170 ms 1024 KB Output is correct
10 Correct 169 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 85 ms 588 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 3 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 207 ms 1020 KB Output is correct
12 Correct 170 ms 972 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 3 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 3 ms 308 KB Output is correct
20 Correct 3 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 19 ms 396 KB Output is correct
28 Correct 19 ms 332 KB Output is correct
29 Correct 19 ms 400 KB Output is correct
30 Correct 19 ms 396 KB Output is correct
31 Correct 17 ms 368 KB Output is correct
32 Correct 120 ms 716 KB Output is correct
33 Correct 81 ms 588 KB Output is correct
34 Correct 173 ms 912 KB Output is correct
35 Correct 184 ms 1020 KB Output is correct
36 Correct 136 ms 716 KB Output is correct
37 Correct 178 ms 1008 KB Output is correct
38 Correct 112 ms 716 KB Output is correct
39 Correct 180 ms 1016 KB Output is correct
40 Correct 182 ms 916 KB Output is correct