답안 #44036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44036 2018-03-29T12:08:37 Z ruhanhabib39 도서관 (JOI18_library) C++17
0 / 100
29 ms 376 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include "library.h"
using namespace std;

namespace {
   int N;

   const int MAXN = 1000;
   vector<int> G[MAXN + 10];

   vector<int> init(int l, int r, int i = -1) {
      vector<int> v(N, 0);
      if(l <= r) fill(v.begin() + l, v.begin() + r + 1, 1);
      if(i != -1) v[i] ^= 1;
      return v;
   }

   map<tuple<int,int,int>,int> cnt;

   int ask(int l, int r, int i = -1) {
      int& res = cnt[{l,r,i}];
      if(res == 0) res = Query(init(l, r, i));
      return res;
   }

   void work(int i, int l, int r, int cc) {
      if(l == r) {
         G[i].push_back(l);
         G[l].push_back(i);
         return;
      }

      int m = (l + r) / 2;

      if(cc == 1) {
         if(ask(0, m) >= ask(0, m, i)) {
            work(i, l, m, 1);
         } else work(i, m+1, r, 1);
      } else {
         bool lYes = ask(0, m) >= ask(0, m, i);
         bool rYes = ask(m+1, i-1) >= ask(m+1, i-1, i);

         if(lYes && rYes) cc = 1;

         if(lYes) {
            work(i, l, m, cc);
         }
         if(rYes) {
            work(i, m+1, r, cc);
         }
      }
   }

   
};

void Solve(int N_) {
   N = N_;
   for(int i = 1; i < N; i++) {
      if(ask(0, i-1) >= ask(0, i)) {
         int cc = ask(0, i-1) == ask(0, i) ? 1 : 2;
         work(i, 0, i-1, cc);
      }
   }
   for(int i = 0; i < N; i++) {
      G[i].erase(unique(G[i].begin(), G[i].end()), G[i].end());
   }
   vector<int> res;
   res.reserve(N);
   int u = 0, p = -1;
   while(G[u].size() > 1) u++;
   while((int)res.size() < N) {
      res.push_back(u+1);
      for(int v : G[u]) {
         if(v != p) {
            p = u;
            u = v;
            break;
         }
      }
   }
   Answer(res);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 376 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 376 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -