Submission #49124

# Submission time Handle Problem Language Result Execution time Memory
49124 2018-05-22T14:15:12 Z aome Sequence (BOI14_sequence) C++17
0 / 100
4 ms 988 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) {
		for (int i = 9; i >= 0; --i) {
			if (vec[0] >> i & 1) cur += i * pw[cnt++];
		}
		if (res > cur) 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.size() < vec.size()) {
			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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Incorrect 3 ms 616 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 616 KB Output is correct
2 Correct 3 ms 680 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
4 Incorrect 2 ms 724 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 988 KB Output is correct
2 Correct 4 ms 988 KB Output is correct
3 Correct 2 ms 988 KB Output is correct
4 Incorrect 2 ms 988 KB Output isn't correct
5 Halted 0 ms 0 KB -