Submission #830180

# Submission time Handle Problem Language Result Execution time Memory
830180 2023-08-18T22:51:53 Z ikaurov Ancient Machine 2 (JOI23_ancient2) C++17
37 / 100
68 ms 516 KB
#include "ancient2.h"
#include <bits/stdc++.h>
using namespace std;
#define all(arr) (arr).begin(), (arr).end()
#define ll long long
#define ld long double
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define endl '\n'

vector<int> prefix_function(string s){
  int n = sz(s);
  vector<int> pi(n);
  for (int i = 1; i < n; i++){
    int k = pi[i - 1];
    while (k && s[k] != s[i]) k = pi[k - 1];
    pi[i] = k + (s[i] == s[k]);
  }
  return pi;
}

vector<vector<int>> build_automaton(string s){
  auto pi = prefix_function(s);
  int n = sz(s);
  vector<vector<int>> aut(2, vector<int>(n + 1));
  for (int i = 0; i <= n; i++){
    for (int c = 0; c < 2; c++){
      if (s[i] == '0' + c) aut[c][i] = i + 1;
      else if (i) aut[c][i] = aut[c][pi[i - 1]];
    }
  }
  return aut;
}

std::string Solve(int n) {
  int half1 = n / 2, half2 = n - half1;
  string s, t;
  for (int i = 0; i < half1; i++){
    vector<int> a(i + 3), b(i + 3);
    iota(all(a), 1);
    iota(all(b), 1);
    a[i] = i + 1, b[i] = i + 2;
    a[i + 1] = b[i + 1] = i + 1;
    a[i + 2] = b[i + 2] = i + 2;
    s.pb(Query(sz(a), a, b) == i + 1? '0' : '1');
  }
  for (int i = 0; i < half2; i++){
    auto aut = build_automaton("0" + t);
    t = (Query(sz(aut[0]), aut[0], aut[1]) == sz(t) + 1? "0" : "1") + t;
  }
  return s + t;
}
# Verdict Execution time Memory Grader output
1 Partially correct 42 ms 296 KB Output is partially correct
2 Partially correct 43 ms 332 KB Output is partially correct
3 Partially correct 51 ms 416 KB Output is partially correct
4 Partially correct 50 ms 424 KB Output is partially correct
5 Partially correct 68 ms 416 KB Output is partially correct
6 Partially correct 46 ms 336 KB Output is partially correct
7 Partially correct 51 ms 464 KB Output is partially correct
8 Partially correct 47 ms 372 KB Output is partially correct
9 Partially correct 49 ms 420 KB Output is partially correct
10 Partially correct 44 ms 424 KB Output is partially correct
11 Partially correct 48 ms 428 KB Output is partially correct
12 Partially correct 43 ms 440 KB Output is partially correct
13 Partially correct 43 ms 428 KB Output is partially correct
14 Partially correct 44 ms 428 KB Output is partially correct
15 Partially correct 45 ms 420 KB Output is partially correct
16 Partially correct 42 ms 336 KB Output is partially correct
17 Partially correct 49 ms 424 KB Output is partially correct
18 Partially correct 48 ms 420 KB Output is partially correct
19 Partially correct 45 ms 424 KB Output is partially correct
20 Partially correct 45 ms 416 KB Output is partially correct
21 Partially correct 47 ms 336 KB Output is partially correct
22 Partially correct 49 ms 420 KB Output is partially correct
23 Partially correct 47 ms 416 KB Output is partially correct
24 Partially correct 42 ms 416 KB Output is partially correct
25 Partially correct 52 ms 396 KB Output is partially correct
26 Partially correct 52 ms 424 KB Output is partially correct
27 Partially correct 46 ms 436 KB Output is partially correct
28 Partially correct 48 ms 428 KB Output is partially correct
29 Partially correct 55 ms 324 KB Output is partially correct
30 Partially correct 43 ms 424 KB Output is partially correct
31 Partially correct 42 ms 312 KB Output is partially correct
32 Partially correct 55 ms 420 KB Output is partially correct
33 Partially correct 48 ms 420 KB Output is partially correct
34 Partially correct 46 ms 424 KB Output is partially correct
35 Partially correct 52 ms 420 KB Output is partially correct
36 Partially correct 43 ms 420 KB Output is partially correct
37 Partially correct 43 ms 408 KB Output is partially correct
38 Partially correct 56 ms 424 KB Output is partially correct
39 Partially correct 55 ms 424 KB Output is partially correct
40 Partially correct 47 ms 424 KB Output is partially correct
41 Partially correct 46 ms 336 KB Output is partially correct
42 Partially correct 46 ms 428 KB Output is partially correct
43 Partially correct 55 ms 424 KB Output is partially correct
44 Partially correct 46 ms 416 KB Output is partially correct
45 Partially correct 44 ms 420 KB Output is partially correct
46 Partially correct 44 ms 336 KB Output is partially correct
47 Partially correct 44 ms 420 KB Output is partially correct
48 Partially correct 47 ms 516 KB Output is partially correct
49 Partially correct 45 ms 420 KB Output is partially correct
50 Partially correct 48 ms 416 KB Output is partially correct
51 Partially correct 43 ms 336 KB Output is partially correct
52 Partially correct 47 ms 416 KB Output is partially correct
53 Partially correct 44 ms 348 KB Output is partially correct
54 Partially correct 44 ms 416 KB Output is partially correct
55 Partially correct 51 ms 336 KB Output is partially correct
56 Partially correct 60 ms 420 KB Output is partially correct
57 Partially correct 43 ms 420 KB Output is partially correct
58 Partially correct 47 ms 476 KB Output is partially correct
59 Partially correct 42 ms 432 KB Output is partially correct
60 Partially correct 43 ms 336 KB Output is partially correct
61 Partially correct 55 ms 432 KB Output is partially correct
62 Partially correct 51 ms 400 KB Output is partially correct
63 Partially correct 43 ms 336 KB Output is partially correct