답안 #21877

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
21877 2017-04-26T15:08:39 Z petrpan 수열 (BOI14_sequence) C++14
컴파일 오류
0 ms 0 KB
#include <iostream> 
#include <cstdio>
#include <vector>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;

const int maxn = 100000 + 123;
int k;
vector<int> d;

void ReadData() {
	cin >> k;
	d.resize(k);
	Rep(i,k) cin >> d[i];
}

long long fromVector(vector<int> d) {
	if (sz(d) == 0) return 0;
	if (sz(d) == 1 && d[0] == 0) {
		return 10;
	}
	if (sz(d) >= 2 && d[0] == 0) {
		swap(d[0], d[1]);
	}
	long long res = 0;
	for (int i = 0; i < (int)d.size() ; i++) {
		res = res * 10 + d[i];
	}
	return res;
}

const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000 + 123;

bool onbit(const int state, const int pos) {
	return ((state >> pos) & 1);
}
int offbit(const int state , const int pos) {
	return state ^ (1 << pos);
}

int total = 0;
long long solve(int pos, vector<vector<int> >  need) {
	if (sz(need) <= 1) {
		if (sz(need) == 0) return 0;
		return fromVector(need[0]);
	}

	long long res = INF;
	vector<int> f;
	f.resize(sz(need));
	for (int i = 0; i < (int)need.size(); ++i) {
		f[i] = 0;
		for (int x : need[i]) f[i] |= (1 << x);
	}
	for (int d = 0; d <= 9; ++d) {
		vector<vector<int> > to;
		bool ok = false;
		int k = d;
		vector<int> g = f;
		for (int i = 0; i < (int)need.size() ; i++) {
			int u = k % 10;
			if (onbit(g[i], u)) {
				g[i] = offbit(g[i],  u)
				ok = true;
			}
			k++;
		}  
		if (!ok) continue;
		vector<int> maskTo(k / 10 + 3, 0);
		k = d;
		for (int i = 0; i < (int)need.size(); i++) {
			maskTo[k / 10] |= g[i];
			k++;
		}
		For(z,0,k / 10) {
			to.push_back(vector<int>(0));
			vector<int> &a = to.back();
			For(l, 0, 9) if (onbit(maskTo[z], l)) a.push_back(l);
		}
		while (sz(to) && sz(to.back()) == 0) to.pop_back();
		long long t = solve(pos + 1, to) * 10 + d;
		if (t == 0 && pos == 1) t = 10;
		res = min(res, t);
	}

	return res;
}

void Process() {
	vector<vector<int> > a(k);
	Rep(i,k) {
		a[i].push_back(d[i]);
	}
	cout << solve(1, a) << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//freopen("input.inp" , "r" , stdin);
	ReadData();
	Process(); 

	return 0;

}

Compilation message

sequence.cpp: In function 'long long int solve(int, std::vector<std::vector<int> >)':
sequence.cpp:73:5: error: expected ';' before 'ok'
     ok = true;
     ^