Submission #43988

# Submission time Handle Problem Language Result Execution time Memory
43988 2018-03-29T08:27:55 Z ruhanhabib39 Library (JOI18_library) C++17
19 / 100
497 ms 1860 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);
      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_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(ask(l, m) >= ask(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(ask(m+1, r) >= ask(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(ask(0, i-1) >= ask(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);
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 504 KB Output is correct
2 Correct 47 ms 564 KB Output is correct
3 Correct 50 ms 696 KB Output is correct
4 Correct 55 ms 720 KB Output is correct
5 Correct 51 ms 720 KB Output is correct
6 Correct 50 ms 720 KB Output is correct
7 Correct 50 ms 720 KB Output is correct
8 Correct 33 ms 720 KB Output is correct
9 Correct 53 ms 760 KB Output is correct
10 Correct 26 ms 760 KB Output is correct
11 Correct 1 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 504 KB Output is correct
2 Correct 47 ms 564 KB Output is correct
3 Correct 50 ms 696 KB Output is correct
4 Correct 55 ms 720 KB Output is correct
5 Correct 51 ms 720 KB Output is correct
6 Correct 50 ms 720 KB Output is correct
7 Correct 50 ms 720 KB Output is correct
8 Correct 33 ms 720 KB Output is correct
9 Correct 53 ms 760 KB Output is correct
10 Correct 26 ms 760 KB Output is correct
11 Correct 1 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Incorrect 497 ms 1860 KB Wrong Answer [3]
18 Halted 0 ms 0 KB -