답안 #49129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49129 2018-05-22T15:10:57 Z aome 수열 (BOI14_sequence) C++17
0 / 100
446 ms 1160 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() && buf.back() == 0) {
			if (buf.size() > 1) {
				swap(buf[buf.size() - 2], buf[buf.size() - 1]);
			}
			else zero = 1;
		}
		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 2 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 3 ms 436 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Incorrect 5 ms 680 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 680 KB Output is correct
2 Correct 5 ms 680 KB Output is correct
3 Correct 3 ms 680 KB Output is correct
4 Correct 3 ms 680 KB Output is correct
5 Correct 2 ms 680 KB Output is correct
6 Correct 2 ms 680 KB Output is correct
7 Correct 9 ms 680 KB Output is correct
8 Correct 4 ms 680 KB Output is correct
9 Incorrect 5 ms 800 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 800 KB Output is correct
2 Correct 46 ms 840 KB Output is correct
3 Correct 57 ms 848 KB Output is correct
4 Correct 53 ms 848 KB Output is correct
5 Correct 83 ms 864 KB Output is correct
6 Incorrect 25 ms 864 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 864 KB Output is correct
2 Correct 6 ms 864 KB Output is correct
3 Correct 3 ms 864 KB Output is correct
4 Correct 4 ms 864 KB Output is correct
5 Correct 446 ms 1160 KB Output is correct
6 Correct 2 ms 1160 KB Output is correct
7 Correct 2 ms 1160 KB Output is correct
8 Correct 6 ms 1160 KB Output is correct
9 Correct 2 ms 1160 KB Output is correct
10 Incorrect 5 ms 1160 KB Output isn't correct
11 Halted 0 ms 0 KB -