| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1328465 | nanaseyuzuki | 도서관 (JOI18_library) | C++20 | 0 ms | 0 KiB |
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
const int mn = 1e5 + 5;
#ifdef LOCAL
#include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h"
#else
#define debug(...) 42
#endif
namespace {
struct Judge
{
int N;
int A[1002];
int pos[1002];
bool f[1002];
int query_c;
bool answered;
void init()
{
query_c=0;
int ret=scanf("%d",&N); ret++;
answered=false;
for(int i=0;i<N;i++)ret=scanf("%d",&A[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)
{
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 n;
vector <int> a[mn], res;
vector <int> merge(vector <int> x, vector <int> y){
vector <int> ans(n);
ans[x.front()] = 1, ans[y.front()] = 1;
if(Query(ans) == 1){
reverse(all(y));
for(auto i : x) y.push_back(i);
return y;
}
ans[x.front()] = 0, ans[y.front()] = 0;
ans[x.front()] = 1, ans[y.back()] = 1;
if(Query(ans) == 1){
for(auto i : x) y.push_back(i);
return y;
}
ans[x.front()] = 0, ans[y.back()] = 0;
ans[x.back()] = 1, ans[y.front()] = 1;
if(Query(ans) == 1){
for(auto i : y) x.push_back(i);
return x;
}
ans[x.back()] = 0, ans[y.front()] = 0;
reverse(all(y));
for(auto i : y) x.push_back(i);
return x;
}
void Solve(int N) {
n = N;
for(int i = 0; i < n; i++) a[i].push_back(i);
for(int st = 0; st < n - 1; st ++){
int l = st + 1, r = n - 1, ans = -1;
while(l <= r){
int mid = (l + r) >> 1;
vector <int> ask(n);
for(int i = st; i <= mid; i++){
for(auto j : a[i]) ask[j] = 1;
}
if(Query(ask) <= mid - st){
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
a[ans] = merge(a[st], a[ans]);
debug(ans, a[ans]);
}
for(int i = 0; i < n; i++) debug(i, a[i]);
debug(a[n - 1]);
for(auto &i : a[n - 1]) i ++;
Answer(a[n - 1]);
}
int main()
{
judge.init();
Solve(judge.N);
judge.end();
}
