/*************************************
* author: marvinthang *
* created: 15.03.2023 10:46:13 *
*************************************/
#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define left ___left
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i) (1LL << (i))
#define BIT(x, i) ((x) >> (i) & 1)
#define __builtin_popcount __builtin_popcountll
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define REPD(i, n) for (int i = (n); i--; )
#define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; )
#define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
#include "debug.h"
#else
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define DB(...) 23
#define db(...) 23
#define debug(...) 23
#endif
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
// end of template
vector <int> findSequence(int N) {
int maxl = N / 2 + 1;
int less = isSubsequence(vector<int>((N + 1) / 2, 0)) ? 1 : 0;
int l = 0, r = N / 2;
while (l <= r) {
int m = l + r >> 1;
if (isSubsequence(vector<int>(m, less))) l = m + 1;
else r = m - 1;
}
int cnt_less = r;
vector <int> res;
int last = 0;
REP(i, cnt_less) {
l = 0, r = maxl - cnt_less + i;
while (l <= r) {
int m = l + r >> 1;
vector <int> v(m, !less);
REP(_, cnt_less - i) v.push_back(less);
if (isSubsequence(v)) l = m + 1;
else r = m - 1;
}
if (r == maxl - cnt_less + i) {
l = 0, r = maxl - i - 1;
while (l <= r) {
int m = l + r >> 1;
vector <int> v(i + 1, less);
REP(_, m) v.push_back(!less);
if (isSubsequence(v)) l = m + 1;
else r = m - 1;
}
r = N - cnt_less - r;
}
REP(_, r - last) res.push_back(!less);
res.push_back(less);
last = r;
}
REP(_, N - cnt_less - last) res.push_back(!less);
return res;
}
#ifdef LOCAL
int N;
vector <int> v;
int L;
bool isSubsequence(vector <int> t) {
assert((int) t.size() <= N);
L = max(L, (int) t.size());
int cur = 0;
for (int i: t) {
while (cur < N && v[cur] != i) ++cur;
if (cur == N) return false;
++cur;
}
return true;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long h) { return uniform_int_distribution <long long> (l, h) (rng); }
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
file("HIDDEN");
bool type;
cin >> N >> type;
v.resize(N);
if (!type) cin >> v;
else REP(i, N) v[i] = rand(0, 1);
vector <int> res = findSequence(N);
assert(res == v);
cout << L << '\n';
cout << v << '\n' << res << '\n';
cerr << "Time elapsed: " << TIME << " s.\n";
return (0^0);
}
#endif
Compilation message
hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
51 | int m = l + r >> 1;
| ~~^~~
hidden.cpp:61:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | int m = l + r >> 1;
| ~~^~~
hidden.cpp:70:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | int m = l + r >> 1;
| ~~^~~
grader.cpp: In function 'int main()':
grader.cpp:28:26: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
28 | fprintf (fifo_out, "%d\n", ans.size ());
| ~^ ~~~~~~~~~~~
| | |
| int std::vector<int>::size_type {aka long unsigned int}
| %ld
grader.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i=0; i<ans.size () && i < N; i++)
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct: Maximum length of a query = 5 |
2 |
Correct |
0 ms |
344 KB |
Output is correct: Maximum length of a query = 6 |
3 |
Correct |
0 ms |
344 KB |
Output is correct: Maximum length of a query = 5 |
4 |
Correct |
1 ms |
344 KB |
Output is correct: Maximum length of a query = 5 |
5 |
Correct |
0 ms |
344 KB |
Output is correct: Maximum length of a query = 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
692 KB |
Output is correct: Maximum length of a query = 83 |
2 |
Correct |
8 ms |
696 KB |
Output is correct: Maximum length of a query = 90 |
3 |
Correct |
9 ms |
688 KB |
Output is correct: Maximum length of a query = 96 |
4 |
Correct |
7 ms |
692 KB |
Output is correct: Maximum length of a query = 77 |
5 |
Correct |
10 ms |
948 KB |
Output is correct: Maximum length of a query = 95 |
6 |
Correct |
8 ms |
960 KB |
Output is correct: Maximum length of a query = 87 |
7 |
Correct |
7 ms |
948 KB |
Output is correct: Maximum length of a query = 97 |
8 |
Correct |
5 ms |
436 KB |
Output is correct: Maximum length of a query = 83 |
9 |
Correct |
7 ms |
700 KB |
Output is correct: Maximum length of a query = 101 |
10 |
Correct |
11 ms |
1196 KB |
Output is correct: Maximum length of a query = 100 |
11 |
Correct |
10 ms |
696 KB |
Output is correct: Maximum length of a query = 96 |
12 |
Correct |
8 ms |
692 KB |
Output is correct: Maximum length of a query = 100 |
13 |
Correct |
9 ms |
700 KB |
Output is correct: Maximum length of a query = 101 |