Submission #44038

# Submission time Handle Problem Language Result Execution time Memory
44038 2018-03-29T12:15:58 Z ruhanhabib39 Library (JOI18_library) C++17
100 / 100
329 ms 1248 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 addEdge(int i, int j) {
      G[i].push_back(j);
      G[j].push_back(i);
   }

   template<class Fn>
   int work(int i, int l, int r, Fn cmp) {
      while(l < r) {
         int m = (l + r) / 2;
         if(cmp(ask(0, m), ask(0, m, i))) r = m;
         else l = m+1;
      }
      return l;
   }

};

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;
         int j = work(i, 0, i-1, greater_equal<int>());
         addEdge(i, j);
         if(cc == 2) {
            j = work(i, j+1, i-1, greater<int>());
            addEdge(i, j);
         }
      }
   }
   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 27 ms 376 KB Output is correct
2 Correct 26 ms 436 KB Output is correct
3 Correct 27 ms 552 KB Output is correct
4 Correct 25 ms 552 KB Output is correct
5 Correct 25 ms 556 KB Output is correct
6 Correct 21 ms 556 KB Output is correct
7 Correct 25 ms 556 KB Output is correct
8 Correct 25 ms 624 KB Output is correct
9 Correct 19 ms 624 KB Output is correct
10 Correct 15 ms 624 KB Output is correct
11 Correct 2 ms 624 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 2 ms 700 KB Output is correct
16 Correct 4 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 376 KB Output is correct
2 Correct 26 ms 436 KB Output is correct
3 Correct 27 ms 552 KB Output is correct
4 Correct 25 ms 552 KB Output is correct
5 Correct 25 ms 556 KB Output is correct
6 Correct 21 ms 556 KB Output is correct
7 Correct 25 ms 556 KB Output is correct
8 Correct 25 ms 624 KB Output is correct
9 Correct 19 ms 624 KB Output is correct
10 Correct 15 ms 624 KB Output is correct
11 Correct 2 ms 624 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 2 ms 700 KB Output is correct
16 Correct 4 ms 700 KB Output is correct
17 Correct 302 ms 1228 KB Output is correct
18 Correct 329 ms 1228 KB Output is correct
19 Correct 268 ms 1248 KB Output is correct
20 Correct 227 ms 1248 KB Output is correct
21 Correct 221 ms 1248 KB Output is correct
22 Correct 255 ms 1248 KB Output is correct
23 Correct 264 ms 1248 KB Output is correct
24 Correct 93 ms 1248 KB Output is correct
25 Correct 249 ms 1248 KB Output is correct
26 Correct 236 ms 1248 KB Output is correct
27 Correct 85 ms 1248 KB Output is correct
28 Correct 284 ms 1248 KB Output is correct
29 Correct 260 ms 1248 KB Output is correct
30 Correct 242 ms 1248 KB Output is correct