답안 #181126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
181126 2020-01-09T07:03:42 Z BThero "The Lyuboyn" code (IZhO19_lyuboyn) C++17
8 / 100
1000 ms 3152 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()


using namespace std;

const bool dbg_flg = 1;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n'
 
const int inf = 1e9 + 7;
const int MAXN = (1 << 18) + 5;

int n, k, t;

string st;

int arr[MAXN];

bool used[MAXN];

int f(int a, int b) {
	return __builtin_popcount(a ^ b);
}

string str(int x) {
	string ret;

	while (x > 0) {
		ret.pb(x % 2 + '0');
		x /= 2;
	}

	while (ret.size() < n) {
		ret.pb('0');
	}

	reverse(ret.begin(), ret.end());
	return ret;
}

void printAns() {
	cout << (1 << n) << endl;

	for (int i = 0; i < (1 << n); ++i) {
		cout << str(arr[i]) << endl;
	}

	exit(0);
}

void rec(int v) {
	if (v == (1 << n) - 1) {
		if (t == 1) {
			if (f(arr[v], arr[0]) == k) {
				printAns();				
			}			
		}
		else {
			printAns();
		}

        return;             
	}

	for (int x = 0; x < (1 << n); ++x) {
		if (!used[x] && f(arr[v], x) == k) {
			used[x] = 1;
			arr[v + 1] = x;
			rec(v + 1);
			used[x] = 0;
		}
	}
}

int bin(string s) {
	reverse(all(s));
	int ret = 0;

	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '1') {
			ret += (1 << i);
		}
	}

	return ret;
}

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> n >> k >> t;
	cin >> st;

	if (k % 2 == 0) {
		cout << -1 << endl;
		return 0;
	}

	arr[0] = bin(st);
	used[bin(st)] = 1;    
	rec(0);
	return 0;
}

Compilation message

lyuboyn.cpp: In function 'std::__cxx11::string str(int)':
lyuboyn.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (ret.size() < n) {
         ~~~~~~~~~~~^~~
lyuboyn.cpp: In function 'int bin(std::__cxx11::string)':
lyuboyn.cpp:86:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.size(); ++i) {
                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 2 ms 376 KB Ok
3 Correct 2 ms 376 KB Ok
4 Correct 2 ms 376 KB Ok
5 Correct 2 ms 376 KB Ok
6 Correct 2 ms 376 KB Ok
7 Correct 7 ms 376 KB Ok
8 Correct 2 ms 376 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1028 ms 2888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Ok
2 Correct 72 ms 940 KB Ok
3 Execution timed out 1026 ms 3152 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1014 ms 2944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1028 ms 2888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1018 ms 1108 KB Time limit exceeded
2 Halted 0 ms 0 KB -