# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
952704 |
2024-03-24T15:34:28 Z |
kilkuwu |
Library (JOI18_library) |
C++17 |
|
13 ms |
696 KB |
#include <bits/stdc++.h>
#ifndef LOCAL
#include "library.h"
#else
#include <vector>
int Query(const std::vector<int>& M);
void Answer(const std::vector<int>& res);
#endif
void Solve(int N) {
std::vector<int> dp(N + 1, -1);
auto get_pref = [&](int x) {
if (dp[x] != -1) return dp[x];
std::vector<int> a(N);
for (int i = 0; i < x; i++) {
a[i] = 1;
}
return dp[x] = Query(a);
};
auto get_pref_more = [&](int x, int y) {
std::vector<int> a(N);
a[y - 1] = 1;
for (int i = 0; i < x; i++) {
a[i] = 1;
}
return Query(a);
};
std::vector<std::vector<int>> adj(N + 1);
dp[1] = 1;
for (int i = 2; i <= N; i++) {
if (get_pref(i) - get_pref(i - 1) == 1) {
continue;
}
if (get_pref(i) - get_pref(i - 1) == 0) {
int lb = 1, rb = i - 1;
while (lb < rb) {
int mid = (lb + rb) / 2;
int bef = get_pref(mid);
int aft = get_pref_more(mid, i);
if (aft - bef == 0) {
rb = mid;
} else {
lb = mid + 1;
}
}
adj[rb].push_back(i);
adj[i].push_back(rb);
continue;
}
assert(get_pref(i) - get_pref(i - 1) == -1);
int lb = 1, rb = i - 1;
while (lb < rb) {
int mid = (lb + rb) / 2;
int bef = get_pref(mid);
int aft = get_pref_more(mid, i);
if (aft - bef == -1) { // now we can be sure
rb = mid;
} else {
lb = mid + 1;
}
}
int z = rb;
adj[z].push_back(i);
adj[i].push_back(z);
lb = 1, rb = z - 1; // z - 1
while (lb < rb) {
int mid = (lb + rb) / 2;
int bef = get_pref(mid);
int aft = get_pref_more(mid, i);
if (aft - bef == 0) {
rb = mid;
} else {
lb = mid + 1;
}
}
adj[rb].push_back(i);
adj[i].push_back(rb);
}
std::vector<int> res;
std::function<void(int, int)> dfs = [&](int u, int p) {
res.push_back(u);
for (int v : adj[u]) {
if (v == p) continue;
dfs(v, u);
}
};
for (int i = 1; i <= N; i++) {
if ((int) adj[i].size() == 1) {
dfs(i, i);
break;
}
}
Answer(res);
}
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
using namespace std;
void Solve(int N);
#ifdef LOCAL
#include "template\debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif
// std::mt19937_64 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
std::mt19937_64 rng(0); // Fixed seed
#define uid(a, b) std::uniform_int_distribution<long long>(a, b)(rng)
namespace {
struct Judge
{
int N;
int A[1002];
int pos[1002];
bool f[1002];
int query_c;
bool answered;
void init()
{
query_c=0;
N = 1000;
answered=false;
std::iota(A, A + N, 1);
std::shuffle(A, A + N, rng);
for (int i = 0; i < N; i++) {
pos[A[i]] = i;
}
}
int query(const vector<int>& M)
{
if(query_c==20000)
{
puts("Wrong Answer [3]");
exit(0);
}
if(int(M.size())!=N)
{
puts("Wrong Answer [1]");
exit(0);
}
bool all_zero=true;
for(int i=0;i<N;i++)
{
if(M[i]!=0&&M[i]!=1)
{
puts("Wrong Answer [2]");
exit(0);
}
if(M[i]==1)all_zero=false;
}
if(all_zero)
{
puts("Wrong Answer [2]");
exit(0);
}
memset(f,0,sizeof(f));
for(int i=0;i<N;i++)if(M[i])f[pos[i+1]]=true;
bool las=false;
int r=0;
for(int i=0;i<N;i++)
{
if(las==false&&f[i]==true)r++;
las=f[i];
}
query_c++;
return r;
}
void answer(const vector<int>& res)
{
bool f1=true,f2=true;
if(int(res.size())!=N)
{
std::cerr << N << std::endl;
for (int i = 0; i < N; i++) {
std::cerr << A[i] << " ";
}
std::cerr << std::endl;
puts("Wrong Answer [4]");
exit(0);
}
if(answered)
{
puts("Wrong Answer [7]");
exit(0);
}
answered=true;
memset(f,0,sizeof(f));
for(int i=0;i<N;i++)
{
if(res[i]<=0||res[i]>N)
{
puts("Wrong Answer [5]");
exit(0);
}
if(f[res[i]])
{
puts("Wrong Answer [6]");
exit(0);
}
f[res[i]]=true;
}
for(int i=0;i<N;i++)
{
f1&=A[i]==res[i];
f2&=A[i]==res[N-i-1];
}
if(!f1&&!f2)
{
puts("Wrong Answer [8]");
exit(0);
}
}
void end()
{
if(!answered)puts("Wrong Answer [7]");
else printf("Accepted : %d\n",query_c);
}
}judge;
}
int Query(const vector<int>& M)
{
return judge.query(M);
}
void Answer(const vector<int>& res)
{
judge.answer(res);
}
int main()
{
while (true) {
judge.init();
Solve(judge.N);
judge.end();
}
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
448 KB |
# of queries: 1453 |
2 |
Correct |
11 ms |
696 KB |
# of queries: 1464 |
3 |
Correct |
13 ms |
444 KB |
# of queries: 1538 |
4 |
Correct |
13 ms |
448 KB |
# of queries: 1534 |
5 |
Correct |
13 ms |
688 KB |
# of queries: 1536 |
6 |
Correct |
13 ms |
688 KB |
# of queries: 1527 |
7 |
Correct |
12 ms |
688 KB |
# of queries: 1541 |
8 |
Correct |
12 ms |
436 KB |
# of queries: 1474 |
9 |
Correct |
11 ms |
440 KB |
# of queries: 1544 |
10 |
Correct |
10 ms |
440 KB |
# of queries: 903 |
11 |
Incorrect |
0 ms |
344 KB |
Wrong Answer [4] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
448 KB |
# of queries: 1453 |
2 |
Correct |
11 ms |
696 KB |
# of queries: 1464 |
3 |
Correct |
13 ms |
444 KB |
# of queries: 1538 |
4 |
Correct |
13 ms |
448 KB |
# of queries: 1534 |
5 |
Correct |
13 ms |
688 KB |
# of queries: 1536 |
6 |
Correct |
13 ms |
688 KB |
# of queries: 1527 |
7 |
Correct |
12 ms |
688 KB |
# of queries: 1541 |
8 |
Correct |
12 ms |
436 KB |
# of queries: 1474 |
9 |
Correct |
11 ms |
440 KB |
# of queries: 1544 |
10 |
Correct |
10 ms |
440 KB |
# of queries: 903 |
11 |
Incorrect |
0 ms |
344 KB |
Wrong Answer [4] |
12 |
Halted |
0 ms |
0 KB |
- |