답안 #368335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
368335 2021-02-19T22:40:06 Z farhan132 도서관 (JOI18_library) C++17
100 / 100
533 ms 492 KB
/***Farhan132***/

#include <bits/stdc++.h>
#ifndef LOCAL
#include "library.h"
#endif
using namespace std;
 
typedef int ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<ll> vll;
typedef pair<ll , ll> ii;
typedef vector< ii > vii;
typedef pair < pair < ll , ll > , pair < ll , ll > > cm; 
 
#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean fflush(stdout)

const ll mod =  (ll)1e9 + 7;
const ll maxn = (ll)2e5 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e9;
 
ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};
#ifdef LOCAL


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);
}
#endif

void Solve(int n){ 
  vector < ll > RES;
  if(n == 1){
    RES.pb(1);
    Answer(RES);
    return;
  }

  set < ll > s;
  for(ll i = 1; i <= n; i++){
    s.in(i);
  }

  ll ans[n+5];
  for(ll i = 1; i <= n; i++){
    s.erase(i);
    vector < ll > q;
    for(ll j = 1; j <= n; j++){
      q.pb(((bool)(s.count(j))));
    }

    if(Query(q) == 1){
      ans[1] = i;
      break;
    }
    s.in(i);
  }
  set < ll > final = s;

  for(ll i = 2; i <= n; i++){
    s = final;
    while(s.size() > 1){
      ll kk = s.size();
      set < ll > save = s;
      ll mid = (s.size()/2);
      vector < ll > q(n, 0);
      ll cnt = 0;
      for(ll j = 0; j < mid; j++){
        ll now = *s.begin();
        q[now-1] = 1; 
        s.erase(now);
      }
      ll x = Query(q);
      q[ans[i-1]-1] = 1;
      ll y = Query(q);
      if(x == y){
        set < ll > f;
        for(auto u : save){
          if(!s.count(u)) f.in(u) ;
        }
        s = f; 
        cnt = 1;
      }
    }
    ans[i] = *s.begin();
    final.erase(ans[i]);
  }
  vector < ll > res;
  for(ll i = 1; i <= n; i++) res.pb(ans[i]);
  Answer(res);
  return;
}
#ifdef LOCAL
 
int main() {
    
    
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #else 
     //   freopen("cbarn2.in", "r", stdin);
     //   freopen("cbarn2.out", "w", stdout);
        //ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    #endif
   judge.init();
   Solve(judge.N);
   judge.end();
 
    return 0;
}
#endif

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:198:10: warning: unused variable 'kk' [-Wunused-variable]
  198 |       ll kk = s.size();
      |          ^~
library.cpp:202:10: warning: variable 'cnt' set but not used [-Wunused-but-set-variable]
  202 |       ll cnt = 0;
      |          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 364 KB # of queries: 2375
2 Correct 51 ms 364 KB # of queries: 2409
3 Correct 45 ms 364 KB # of queries: 2648
4 Correct 50 ms 364 KB # of queries: 2595
5 Correct 64 ms 364 KB # of queries: 2508
6 Correct 51 ms 364 KB # of queries: 2551
7 Correct 50 ms 364 KB # of queries: 2544
8 Correct 52 ms 364 KB # of queries: 2420
9 Correct 45 ms 364 KB # of queries: 2546
10 Correct 27 ms 364 KB # of queries: 1474
11 Correct 0 ms 364 KB # of queries: 0
12 Correct 1 ms 364 KB # of queries: 1
13 Correct 1 ms 364 KB # of queries: 4
14 Correct 1 ms 364 KB # of queries: 7
15 Correct 2 ms 364 KB # of queries: 77
16 Correct 3 ms 364 KB # of queries: 183
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 364 KB # of queries: 2375
2 Correct 51 ms 364 KB # of queries: 2409
3 Correct 45 ms 364 KB # of queries: 2648
4 Correct 50 ms 364 KB # of queries: 2595
5 Correct 64 ms 364 KB # of queries: 2508
6 Correct 51 ms 364 KB # of queries: 2551
7 Correct 50 ms 364 KB # of queries: 2544
8 Correct 52 ms 364 KB # of queries: 2420
9 Correct 45 ms 364 KB # of queries: 2546
10 Correct 27 ms 364 KB # of queries: 1474
11 Correct 0 ms 364 KB # of queries: 0
12 Correct 1 ms 364 KB # of queries: 1
13 Correct 1 ms 364 KB # of queries: 4
14 Correct 1 ms 364 KB # of queries: 7
15 Correct 2 ms 364 KB # of queries: 77
16 Correct 3 ms 364 KB # of queries: 183
17 Correct 527 ms 492 KB # of queries: 17982
18 Correct 472 ms 492 KB # of queries: 17293
19 Correct 515 ms 492 KB # of queries: 17467
20 Correct 399 ms 492 KB # of queries: 16325
21 Correct 418 ms 492 KB # of queries: 15324
22 Correct 467 ms 492 KB # of queries: 17669
23 Correct 501 ms 492 KB # of queries: 17224
24 Correct 166 ms 364 KB # of queries: 7915
25 Correct 533 ms 492 KB # of queries: 17136
26 Correct 454 ms 492 KB # of queries: 15963
27 Correct 188 ms 364 KB # of queries: 8040
28 Correct 464 ms 492 KB # of queries: 15957
29 Correct 514 ms 492 KB # of queries: 15939
30 Correct 460 ms 492 KB # of queries: 15957