답안 #49130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49130 2018-05-22T15:16:41 Z aome 수열 (BOI14_sequence) C++17
100 / 100
775 ms 4512 KB
#include <bits/stdc++.h>
 
using namespace std;
 
long long pw[18];
long long res = 1e18;
bool in[10];
 
void go(vector<int> vec, long long cur, int cnt, bool zero) {
	if (vec.size() == 1) {
		vector<int> buf;
		for (int i = 9; i >= 0; --i) {
			if (vec[0] >> i & 1) buf.push_back(i);
		}
		if (buf.size() == 1 && buf[0] == 0) zero = 1;
		else if (buf.size() && buf.back() == 0) {
			swap(buf[buf.size() - 2], buf[buf.size() - 1]), zero = 0;
		}
		else if (buf.size()) zero = 0;
		for (auto i : buf) cur += i * pw[cnt++];
		if (zero) cur += pw[cnt];	
		res = min(res, cur);
		return;
	}

	vector<int> buf;
	int j = 0, mask = 0;
	bool flag = 0;
	for (auto i : vec) {
		if (!j && !flag) {}
		else if (i >> j & 1) i ^= 1 << j;
		mask |= i, j++;
		if (j == 10) {
			buf.push_back(mask), mask = j = 0;
			flag = 1;
		}
	}
	if (j) buf.push_back(mask);
	if (buf.size() == 1 && !buf[0]) res = min(res, cur);

	for (int i = 0; i < 10; ++i) {
		vector<int> buf;
		int k = i, mask = 0;
		for (auto j : vec) {
			if (j >> k & 1) j ^= 1 << k;
			mask |= j, k++;
			if (k == 10) {
				buf.push_back(mask), mask = k = 0;
			}  
		}
		if (k) buf.push_back(mask);
		if (buf != vec) {
			go(buf, cur + i * pw[cnt], cnt + 1, !i);
		}
	}
}
 
int main() {
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> vec;
	for (int i = 0; i < n; ++i) {
		int x; cin >> x, vec.push_back(1 << x);
	}
	pw[0] = 1;
	for (int i = 1; i < 18; ++i) pw[i] = pw[i - 1] * 10;
	go(vec, 0, 0, 0);
	cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 3 ms 412 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 428 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 5 ms 668 KB Output is correct
9 Correct 3 ms 668 KB Output is correct
10 Correct 9 ms 700 KB Output is correct
11 Correct 9 ms 700 KB Output is correct
12 Correct 4 ms 700 KB Output is correct
13 Correct 4 ms 700 KB Output is correct
14 Correct 10 ms 800 KB Output is correct
15 Correct 17 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 852 KB Output is correct
2 Correct 7 ms 852 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 3 ms 852 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 7 ms 852 KB Output is correct
8 Correct 3 ms 852 KB Output is correct
9 Correct 7 ms 852 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 16 ms 852 KB Output is correct
12 Correct 11 ms 852 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 4 ms 852 KB Output is correct
15 Correct 4 ms 852 KB Output is correct
16 Correct 17 ms 852 KB Output is correct
17 Correct 9 ms 852 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
19 Correct 5 ms 892 KB Output is correct
20 Correct 9 ms 892 KB Output is correct
21 Correct 4 ms 892 KB Output is correct
22 Correct 9 ms 892 KB Output is correct
23 Correct 9 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 892 KB Output is correct
2 Correct 44 ms 944 KB Output is correct
3 Correct 37 ms 944 KB Output is correct
4 Correct 44 ms 944 KB Output is correct
5 Correct 47 ms 944 KB Output is correct
6 Correct 18 ms 944 KB Output is correct
7 Correct 139 ms 1584 KB Output is correct
8 Correct 176 ms 1584 KB Output is correct
9 Correct 304 ms 2212 KB Output is correct
10 Correct 281 ms 2404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2404 KB Output is correct
2 Correct 6 ms 2404 KB Output is correct
3 Correct 3 ms 2404 KB Output is correct
4 Correct 4 ms 2404 KB Output is correct
5 Correct 335 ms 2404 KB Output is correct
6 Correct 2 ms 2404 KB Output is correct
7 Correct 2 ms 2404 KB Output is correct
8 Correct 6 ms 2404 KB Output is correct
9 Correct 2 ms 2404 KB Output is correct
10 Correct 4 ms 2404 KB Output is correct
11 Correct 265 ms 2556 KB Output is correct
12 Correct 515 ms 2832 KB Output is correct
13 Correct 2 ms 2832 KB Output is correct
14 Correct 13 ms 2832 KB Output is correct
15 Correct 8 ms 2832 KB Output is correct
16 Correct 8 ms 2832 KB Output is correct
17 Correct 4 ms 2832 KB Output is correct
18 Correct 3 ms 2832 KB Output is correct
19 Correct 10 ms 2832 KB Output is correct
20 Correct 16 ms 2832 KB Output is correct
21 Correct 4 ms 2832 KB Output is correct
22 Correct 5 ms 2832 KB Output is correct
23 Correct 10 ms 2832 KB Output is correct
24 Correct 7 ms 2832 KB Output is correct
25 Correct 10 ms 2832 KB Output is correct
26 Correct 10 ms 2832 KB Output is correct
27 Correct 39 ms 2832 KB Output is correct
28 Correct 38 ms 2832 KB Output is correct
29 Correct 40 ms 2832 KB Output is correct
30 Correct 39 ms 2832 KB Output is correct
31 Correct 23 ms 2832 KB Output is correct
32 Correct 151 ms 2832 KB Output is correct
33 Correct 156 ms 2832 KB Output is correct
34 Correct 199 ms 3356 KB Output is correct
35 Correct 205 ms 3640 KB Output is correct
36 Correct 566 ms 3640 KB Output is correct
37 Correct 738 ms 4008 KB Output is correct
38 Correct 428 ms 4008 KB Output is correct
39 Correct 775 ms 4316 KB Output is correct
40 Correct 739 ms 4512 KB Output is correct