답안 #49127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49127 2018-05-22T14:55:50 Z aome 수열 (BOI14_sequence) C++17
0 / 100
370 ms 1360 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) {
	if (vec.size() == 1) {
		vector<int> buf;
		for (int i = 9; i >= 0; --i) {
			if (vec[0] >> i & 1) buf.push_back(i);
		}
		bool flag = 0;
		if (buf.size() && buf.back() == 0) {
			if (buf.size() > 1) {
				swap(buf[buf.size() - 2], buf[buf.size() - 1]);
			}
			else flag = 1;
		}
		for (auto i : buf) cur += i * pw[cnt++];
		if (flag) cur += pw[cnt];
		res = min(res, cur);
		return;
	}
	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);
		}
	}
}
 
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);
	cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Incorrect 2 ms 552 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 552 KB Output is correct
2 Correct 6 ms 644 KB Output is correct
3 Correct 3 ms 644 KB Output is correct
4 Correct 3 ms 644 KB Output is correct
5 Correct 3 ms 732 KB Output is correct
6 Incorrect 2 ms 732 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 732 KB Output is correct
2 Correct 50 ms 840 KB Output is correct
3 Correct 43 ms 852 KB Output is correct
4 Incorrect 60 ms 924 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 924 KB Output is correct
2 Correct 5 ms 924 KB Output is correct
3 Correct 4 ms 924 KB Output is correct
4 Correct 4 ms 924 KB Output is correct
5 Correct 370 ms 1360 KB Output is correct
6 Correct 3 ms 1360 KB Output is correct
7 Incorrect 2 ms 1360 KB Output isn't correct
8 Halted 0 ms 0 KB -