이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Challenge: Accepted
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <utility>
#include <assert.h>
using namespace std;
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cout << a << " "; debug(b...);}
template <class T> void pary(T l, T r) {
while (l != r) {cout << *l << " ";l++;}
cout << endl;
}
#define ll long long
#define ld long double
#define maxn 400005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
vector<int> ans, v;
void build(int n) {
v.push_back(0);
int cur = 0;
for (int i = 1;i < (1<<n);i++) {
cur ^= i & (-i);
v.push_back(cur);
}
}
void print(int x, int n) {
for (int i = 0;i < n;i++) cout << ((x & (1<<i)) ? 1 : 0);
cout << "\n";
}
void solve(int n, int k, int se) {
//debug(n, k);
//print(se, 6);
if (n == k + 1) {
for (int i = 0;i < v.size();i++) ans.push_back(se ^ v[i]);
return;
}
solve(n - 1, k, se);
int cnt = 0, tmp = ans.back() ^ se;
for (int i = 0;i < n;i++) {
if ((ans.back() ^ se) & (1<<i)) {
if (cnt < k - 1) tmp ^= (1<<i), cnt++;
}
}
tmp ^= (1<<(n - 1));
solve(n - 1, k, se ^ tmp);
}
int main() {
io
int n, k, cy;
cin >> n >> k >> cy;
int st = 0;
for (int i = 0;i < n;i++) {
char c;
cin >> c;
st += (1<<i) * (c - '0');
}
if (k % 2 == 0) {
cout << -1 << "\n";
return 0;
}
cout << (1<<n) << "\n";
if (k == 1) {
build(n);
for (int i = 0;i < (1<<n);i++) print(v[i] ^ st, n);
} else {
build(k + 1);
for (int i = 1;i < (1<<(k + 1));i+=2) {
v[i] ^= (1<<(k + 1)) - 1;
}
solve(n, k, 0);
for (int i:ans) print(i ^ st, n);
}
}
컴파일 시 표준 에러 (stderr) 메시지
lyuboyn.cpp: In function 'void solve(int, int, int)':
lyuboyn.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 0;i < v.size();i++) ans.push_back(se ^ v[i]);
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |