#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef local
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define pary(a...) danb(#a, a)
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
int cnt = sizeof...(T);
((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
std::cerr << "\033[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
std::cerr << (f++ ? ", " : "") << *L;
std::cerr << " ]\033[0m\n";
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back
#define sort_uni(v) sort(all(v)),v.erase(unique(all(v)), v.end())
using namespace std;
using ll = int64_t;
const int maxn = 1000025, LGC = 29;
map<int,int> cnt;
void dfs(int maxLen, string s, array<int,4> dp) {
if (dp[0] + dp[1] + dp[2] + dp[3] - 1 > maxLen) return;
++cnt[dp[0]+dp[1]+dp[2]+dp[3] - 1];
if (s.size() == maxLen) return;
for (char c: {'0', '1'}) {
array<int,4> ndp = {0, 0, 0, 0};
if (c == '0') {
ndp[0] += dp[0];
ndp[0] += dp[1];
ndp[3] += dp[1];
ndp[2] += dp[2];
ndp[3] += dp[3];
ndp[2] += dp[3];
} else {
ndp[0] += dp[0];
ndp[0] += dp[2];
ndp[3] += dp[2];
ndp[1] += dp[1];
ndp[3] += dp[3];
ndp[1] += dp[3];
}
dfs(maxLen, s + c, ndp);
}
// debug(s);
}
int f(int x) {
int res = 0;
while (x) {
res = (res << 1) | (x & 1);
x >>= 1;
}
return res + 1;
}
using BS = bitset<8>;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
dfs(2000, "", {0, 0, 0, 1});
int T;
cin >> T;
while (T--) {
int k;
cin >> k;
cout << cnt[k] << '\n';
cout << -1 << '\n';
}
}
Compilation message
binary.cpp: In function 'void dfs(int, std::string, std::array<int, 4>)':
binary.cpp:34:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
34 | if (s.size() == maxLen) return;
| ~~~~~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
348 ms |
4812 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
348 ms |
4812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
349 ms |
4812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |