이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
typedef long long ll;
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 4e4;
const int M = 4500;
const int L = 19;
int n, k, t, s;
bool flag[N];
vector<int> ans;
vector<int> good;
bool used[N];
void dfs(int v){
used[v] = true;
ans.push_back(v);
int cnt = 0;
for (int x : good){
if (ans.size() == (1 << n)) break;
int u = x ^ v;
if (!used[u]) dfs(u), cnt++;
}
if (cnt == 0 && (ans.size() != (1 << n) || !flag[s ^ v])){
cout << -1;
exit(0);
}
}
bool check(vector<int> &v){
if (ans.size() != (1 << n)) return false;
for (int i = 1; i < v.size(); i++){
if (!flag[v[i - 1] ^ v[i]]) return false;
}
return (t == 0 || flag[v[0] ^ v.back()]);
}
void solve(int TC) {
cin >> n >> k >> t >> s;
for (int mask = 0; mask < (1 << n); mask++){
if (__builtin_popcount(mask) == k) good.push_back(mask), flag[mask] = true;
}
dfs(s);
if (check(ans)){
cout << ans.size() << endl;
for (int x : ans){
for (int i = n - 1; i >= 0; i--){
cout << ((x & (1 << i)) > 0);
}
cout << endl;
}
} else cout << -1;
}
int main() {
startTime = clock();
ios_base::sync_with_stdio(false);
bool llololcal = false;
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
llololcal = true;
#endif
int TC = 1;
//cin >> TC;
for (int test = 1; test <= TC; test++) {
debug(test);
solve(test);
}
if (llololcal) cerr << endl << "Time: " << getCurrentTime() * 1000 << " ms" << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
lyuboyn.cpp: In function 'void dfs(int)':
lyuboyn.cpp:52:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
52 | if (ans.size() == (1 << n)) break;
| ~~~~~~~~~~~^~~~~~~~~~~
lyuboyn.cpp:57:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
57 | if (cnt == 0 && (ans.size() != (1 << n) || !flag[s ^ v])){
| ~~~~~~~~~~~^~~~~~~~~~~
lyuboyn.cpp: In function 'bool check(std::vector<int>&)':
lyuboyn.cpp:65:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
65 | if (ans.size() != (1 << n)) return false;
| ~~~~~~~~~~~^~~~~~~~~~~
lyuboyn.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 1; i < v.size(); i++){
| ~~^~~~~~~~~~
lyuboyn.cpp: In function 'int main()':
lyuboyn.cpp:18:20: warning: statement has no effect [-Wunused-value]
18 | #define debug(...) 42
| ^~
lyuboyn.cpp:109:9: note: in expansion of macro 'debug'
109 | debug(test);
| ^~~~~
# | 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... |