#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] : ", args)
void kout() { cerr << endl; }
template<class T, class ...U>
void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
void debug(auto L, auto R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
vector<int> ans{0,1,0,0,0,0,0,0,0,1,1};
int mxq;
bool isSubsequence(vector<int> a) {
for (int i = 0, j = 0;i < a.size();++i) {
while (j < ans.size() && ans[j] != a[i])
++j;
if (j == ans.size()) return false;
++j;
}
mxq = max(mxq, (int)a.size());
return true;
}
#else
#include "grader.h"
#define debug(...) 0
#define DE(...) 0
#endif
const int MAX_N = 300010, inf = 1e9;
const vector<int> zero{0}, one{1};
int n;
bool query(vector<int> a) {
if (a.size() > n) return false;
return isSubsequence(a);
}
vector<int> operator + (vector<int> a, const vector<int> &b) {
a.insert(end(a), AI(b));
return a;
}
vector<pair<int,int>> edge[MAX_N];
int dp[MAX_N];
vector<int> findSequence(int _n) {
n = _n;
int flip = 0;
auto makev = [&](int a, int v1, int b, int v2, int c, int v3) {
vector<int> res(a+b+c);
for (int i = 0;i < a;++i)
res[i] = v1^flip;
for (int i = a;i < a+b;++i)
res[i] = v2^flip;
for (int i = a+b;i < a+b+c;++i)
res[i] = v3^flip;
return res;
};
auto con = [&](int l, int r, int sum) {
DE(l, r, sum);
edge[r].pb(l-1, -sum);
};
auto concon = [&](int l, int r, int sum) {
edge[l-1].pb(r, sum);
};
DE(n);
vector<int> Z, O, ans;
while (Z.size() == O.size() && Z.size() + O.size() < n) {
if (query(Z + zero))
Z.pb(0);
if (query(O + one))
O.pb(1);
}
if (Z.size() > O.size())
swap(Z, O), flip ^= 1;
while (Z.size () + O.size () < n)
O.pb(0);
int m = Z.size();
//con(1, m+1, O.size());
auto bellmand = [&]() {
dp[m+1] = O.size();
fill(dp+1, dp+m+1, inf);
queue<int> q;
vector<bool> inq(m+2);
auto mpush = [&](int x) {
if (inq[x]) return;
inq[x] = true;
q.emplace(x);
};
mpush(0), mpush(m+1);
while (q.size()) {
int x = q.front(); q.pop();
inq[x] = false;
for (auto [u, w] : edge[x])
if (dp[x] + w < dp[u]) {
dp[u] = dp[x] + w;
mpush(u);
}
}
};
//const int lim = (n * 3 + 3) / 4;
const int lim = ((n) / 2) + 1;
for (int l0 = 0 ; l0 <= m ; ++l0) {
int bound = lim - l0;
for (int r0 = 0 ; r0 + l0 <= m ; ++r0) {
//int mx1 = 0;
if (l0 && r0) break;
bound = min(bound, lim - l0 - r0);
while (!query(makev(l0, 0, bound, 1, r0, 0)))
--bound;
int mx1 = bound;
con(l0+1, m+1 - r0, mx1);
if (l0 + r0 + mx1 < lim)
concon(l0+1, m+1 - r0, mx1);
}
}
bellmand();
for (int i = m+1;i >= 1;--i)
dp[i] -= dp[i-1];
for (int i = 1;i <= m+1;++i) {
while (dp[i]--)
ans.pb( 1 ^ flip );
if (i <= m)
ans.pb( 0 ^ flip );
}
return ans;
}
#ifdef KEV
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
vector<int> res = findSequence(ans.size());
if (res == ans) {
cerr << "AC!\n";
DE(mxq);
}
else {
cerr << "WA\n";
debug(AI(res));
cerr << "Should be\n";
debug(AI(ans));
}
}
#endif
Compilation message
hidden.cpp: In function 'bool query(std::vector<int>)':
hidden.cpp:36:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | if (a.size() > n) return false;
| ~~~~~~~~~^~~
hidden.cpp: In lambda function:
hidden.cpp:30:17: warning: statement has no effect [-Wunused-value]
30 | #define DE(...) 0
| ^
hidden.cpp:61:3: note: in expansion of macro 'DE'
61 | DE(l, r, sum);
| ^~
hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:30:17: warning: statement has no effect [-Wunused-value]
30 | #define DE(...) 0
| ^
hidden.cpp:67:2: note: in expansion of macro 'DE'
67 | DE(n);
| ^~
hidden.cpp:71:53: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
71 | while (Z.size() == O.size() && Z.size() + O.size() < n) {
| ~~~~~~~~~~~~~~~~~~~~^~~
hidden.cpp:84:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
84 | while (Z.size () + O.size () < n)
| ~~~~~~~~~~~~~~~~~~~~~~^~~
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 |
6 ms |
7424 KB |
Output is correct: Maximum length of a query = 5 |
2 |
Correct |
6 ms |
7424 KB |
Output is correct: Maximum length of a query = 6 |
3 |
Correct |
5 ms |
7424 KB |
Output is correct: Maximum length of a query = 5 |
4 |
Correct |
5 ms |
7296 KB |
Output is correct: Maximum length of a query = 5 |
5 |
Correct |
5 ms |
7424 KB |
Output is correct: Maximum length of a query = 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
7424 KB |
Output is correct: Maximum length of a query = 83 |
2 |
Correct |
19 ms |
7424 KB |
Output is correct: Maximum length of a query = 90 |
3 |
Correct |
16 ms |
7424 KB |
Output is correct: Maximum length of a query = 96 |
4 |
Correct |
19 ms |
7424 KB |
Output is correct: Maximum length of a query = 77 |
5 |
Correct |
14 ms |
7424 KB |
Output is correct: Maximum length of a query = 95 |
6 |
Correct |
14 ms |
7424 KB |
Output is correct: Maximum length of a query = 87 |
7 |
Correct |
25 ms |
7424 KB |
Output is correct: Maximum length of a query = 97 |
8 |
Correct |
26 ms |
7424 KB |
Output is correct: Maximum length of a query = 83 |
9 |
Correct |
30 ms |
7424 KB |
Output is correct: Maximum length of a query = 101 |
10 |
Correct |
28 ms |
7424 KB |
Output is correct: Maximum length of a query = 100 |
11 |
Correct |
15 ms |
7424 KB |
Output is correct: Maximum length of a query = 96 |
12 |
Correct |
45 ms |
7424 KB |
Output is correct: Maximum length of a query = 100 |
13 |
Correct |
15 ms |
7552 KB |
Output is correct: Maximum length of a query = 101 |