답안 #43987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43987 2018-03-29T08:22:55 Z ruhanhabib39 도서관 (JOI18_library) C++17
19 / 100
550 ms 732 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#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);
      fill(v.begin() + l, v.begin() + r + 1, 1);
      if(i != -1) v[i] = 1;
      return v;
   }

   void work_left(int i, int l, int r) {
      if(l == r) {
         G[i].push_back(l);
         G[l].push_back(i);
         return;
      }
      int m = (l + r) / 2;
      if(Query(init(l, m)) >= Query(init(l, m, i))) {
         work_left(i, l, m);
      } else {
         work_left(i, m+1, r);
      } 
   }
   void work_right(int i, int l, int r) {
      if(l == r) {
         G[i].push_back(l);
         G[l].push_back(i);
         return;
      }
      int m = (l + r) / 2;
      if(Query(init(m+1, r)) >= Query(init(m+1, r, i))) {
         work_right(i, m+1, r);
      } else {
         work_right(i, l, m);
      }
   }
};

void Solve(int N_) {
   N = N_;
   for(int i = 1; i < N; i++) {
      if(Query(init(0, i-1)) >= Query(init(0, i))) {
         work_left(i, 0, i-1);
         work_right(i, 0, i-1);
      }
   }
   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 Correct 55 ms 248 KB Output is correct
2 Correct 46 ms 440 KB Output is correct
3 Correct 58 ms 544 KB Output is correct
4 Correct 54 ms 544 KB Output is correct
5 Correct 63 ms 544 KB Output is correct
6 Correct 41 ms 584 KB Output is correct
7 Correct 89 ms 588 KB Output is correct
8 Correct 67 ms 700 KB Output is correct
9 Correct 61 ms 700 KB Output is correct
10 Correct 33 ms 700 KB Output is correct
11 Correct 1 ms 700 KB Output is correct
12 Correct 2 ms 700 KB Output is correct
13 Correct 2 ms 700 KB Output is correct
14 Correct 2 ms 700 KB Output is correct
15 Correct 4 ms 700 KB Output is correct
16 Correct 5 ms 700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 248 KB Output is correct
2 Correct 46 ms 440 KB Output is correct
3 Correct 58 ms 544 KB Output is correct
4 Correct 54 ms 544 KB Output is correct
5 Correct 63 ms 544 KB Output is correct
6 Correct 41 ms 584 KB Output is correct
7 Correct 89 ms 588 KB Output is correct
8 Correct 67 ms 700 KB Output is correct
9 Correct 61 ms 700 KB Output is correct
10 Correct 33 ms 700 KB Output is correct
11 Correct 1 ms 700 KB Output is correct
12 Correct 2 ms 700 KB Output is correct
13 Correct 2 ms 700 KB Output is correct
14 Correct 2 ms 700 KB Output is correct
15 Correct 4 ms 700 KB Output is correct
16 Correct 5 ms 700 KB Output is correct
17 Incorrect 550 ms 732 KB Wrong Answer [3]
18 Halted 0 ms 0 KB -