Submission #1070087

# Submission time Handle Problem Language Result Execution time Memory
1070087 2024-08-22T11:34:59 Z bleahbleah Beech Tree (IOI23_beechtree) C++17
26 / 100
2000 ms 136244 KB
#include "beechtree.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 3e5 + 5;

const int mod = 998244853;
struct Mint {
  int val;
  Mint(ll x = 0): val((x % mod + mod) % mod) {;}
  Mint operator +(const Mint& x) const { return Mint(val + x.val); }
  Mint operator -(const Mint& x) const { return Mint(val - x.val); }
  Mint operator *(const Mint& x) const { return Mint((ll)val * x.val); }
  Mint operator +=(const Mint& x) { return *this = Mint(val + x.val); }
  Mint operator -=(const Mint& x) { return *this = Mint(val - x.val); }
  Mint operator *=(const Mint& x) { return *this = Mint((ll)val * x.val); }
  Mint operator ^(const int& _b) const {
    Mint accum = 1, a = *this;
    int b = _b;
    while(b) {
      accum = (b & 1? accum * a : accum);
      a *= a;
      b >>= 1;
    }
    return accum;
  }
  Mint operator /(const Mint& x) { return Mint((ll)val * (x ^ (mod - 2)).val); }
  Mint operator /=(const Mint& x) { return *this = Mint((ll)val * (x ^ (mod - 2)).val); }
};

Mint p[2][nmax];

#define hash bjsefdjhsdsfhoi
struct hash {
   Mint v[2];
   int len;
   hash(Mint a = 0, Mint b = 0, int c = 0) { v[0] = a; v[1] = b; len = c; }
   hash operator +(const hash& x) const {
      return hash(v[0] * p[0][x.len] + x.v[0], v[1] * p[1][x.len] + x.v[1], len + x.len);
   }
   hash operator -(const hash& x) const {
      return hash(v[0] - p[0][len - x.len] * x.v[0], v[1] - p[1][len - x.len] * x.v[1], len - x.len); 
   }
   bool operator !=(const hash& x) const {
      return v[0].val != x.v[0].val || v[1].val != x.v[1].val || len != x.len;
   }
   ll operator()() const { return (ll)v[0].val * mod + v[1].val; }
};



vector<pii> g[nmax];
vector<int> P, C;

unordered_set<int> colors[nmax], play[nmax];
bool isanc(unordered_set<int>& A, unordered_set<int>& B) {
   if(sz(A) < sz(B)) return 0;
   for(auto &x : B)
      if(!A.count(x)) return 0;
   return 1;
}

vector<int> sol;
int h[nmax];

int area[nmax];
hash subarb[nmax];

bool superimposable(int x, int y) { // x peste y 
   if(sz(g[x]) == 0 || x == y) return 1;
   if(subarb[x]() == subarb[y]()) return 1;
   //if(calc[x][y]) return SI[x][y];
   map<int, int> gy;
   for(auto [a, c] : g[y]) gy[c] = a;
   //calc[x][y] = 1;
   //SI[x][y] = 1; 
   for(auto [a, c] : g[x]) {
      if(gy.count(c) == 0) { return 0; }
      if(!superimposable(a, gy[c])) { return 0; }
   }
   return 1;
}

void insert(int& works, map<int, int>& st, int node) {
   if(!works) return;
   auto it = st.upper_bound(area[node]);
   if(it == st.end());
   else if(!superimposable(node, it -> second)) { works = 0; return; }
   if(it == st.begin()); 
   else if(!superimposable(prev(it) -> second, node)) { works = 0; return; }
   st[area[node]] = node;
   return;
}

map<int, int> dfs(int node) {
   map<int, int> here;
   sol[node] = 1;
   area[node] = 1;
   
   vector<hash> fils;
   
   for(auto [x, c] : g[node]) {
      auto T = dfs(x);
      fils.emplace_back(hash(c) + subarb[x]);
      area[node] += area[x];
      sol[node] &= sol[x];
      if(sz(T) > sz(here)) swap(here, T);
      for(auto [a, x] : T) insert(sol[node], here, x);
   }
   
   sort(all(fils), [&](auto a, auto b) { return a() < b(); });
   subarb[node] = hash(11);
   for(auto x : fils) subarb[node] = subarb[node] + x;
   subarb[node] = subarb[node] + hash(12);
   
   insert(sol[node], here, node);
   if(sz(g[node]) != sz(colors[node])) sol[node] = 0;
   return here;
}

std::vector<int> beechtree(int N, int M, std::vector<int> P_, std::vector<int> C_) {
   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
   p[0][0] = p[1][0] = 1;
   p[0][1] = rng() % (mod - 1000) + 503;
   p[1][1] = rng() % (mod - 1200) + 505;
   for(int i = 2; i < nmax; i++)
      p[0][i] = p[0][i - 1] * p[0][1],
      p[1][i] = p[1][i - 1] * p[1][1];
      
   P = P_;
   C = C_;
   for(int i = 1; i < N; i++) {
      g[P[i]].emplace_back(i, C[i]);
      colors[P[i]].emplace(C[i]);
   }
   sol.assign(N, 0);
   dfs(0);
   
   
   return sol;
}

/**
      Töte es durch genaue Untersuchung\Töte es kann es nur noch schlimmer machen\Es lässt es irgendwie atmen
--
*/ 
# Verdict Execution time Memory Grader output
1 Correct 12 ms 48476 KB Output is correct
2 Correct 11 ms 48376 KB Output is correct
3 Correct 13 ms 48472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48476 KB Output is correct
2 Correct 12 ms 48476 KB Output is correct
3 Correct 12 ms 48476 KB Output is correct
4 Correct 11 ms 48476 KB Output is correct
5 Correct 12 ms 48576 KB Output is correct
6 Correct 11 ms 48476 KB Output is correct
7 Correct 12 ms 48476 KB Output is correct
8 Correct 12 ms 48476 KB Output is correct
9 Correct 13 ms 48360 KB Output is correct
10 Correct 12 ms 48476 KB Output is correct
11 Correct 16 ms 48476 KB Output is correct
12 Correct 12 ms 48576 KB Output is correct
13 Correct 12 ms 48476 KB Output is correct
14 Correct 17 ms 48376 KB Output is correct
15 Correct 11 ms 48476 KB Output is correct
16 Correct 13 ms 48476 KB Output is correct
17 Correct 12 ms 48476 KB Output is correct
18 Correct 11 ms 48476 KB Output is correct
19 Correct 12 ms 48472 KB Output is correct
20 Correct 13 ms 48356 KB Output is correct
21 Correct 13 ms 48572 KB Output is correct
22 Correct 13 ms 48332 KB Output is correct
23 Correct 12 ms 48476 KB Output is correct
24 Correct 12 ms 48336 KB Output is correct
25 Correct 12 ms 48472 KB Output is correct
26 Correct 11 ms 48476 KB Output is correct
27 Correct 12 ms 48356 KB Output is correct
28 Correct 12 ms 48476 KB Output is correct
29 Correct 12 ms 48476 KB Output is correct
30 Correct 14 ms 48476 KB Output is correct
31 Correct 12 ms 48476 KB Output is correct
32 Correct 15 ms 48476 KB Output is correct
33 Correct 12 ms 48472 KB Output is correct
34 Correct 12 ms 48476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48476 KB Output is correct
2 Correct 12 ms 48476 KB Output is correct
3 Correct 12 ms 48476 KB Output is correct
4 Correct 11 ms 48476 KB Output is correct
5 Correct 12 ms 48576 KB Output is correct
6 Correct 11 ms 48476 KB Output is correct
7 Correct 128 ms 136152 KB Output is correct
8 Correct 119 ms 136016 KB Output is correct
9 Correct 13 ms 48476 KB Output is correct
10 Correct 12 ms 48660 KB Output is correct
11 Correct 12 ms 48476 KB Output is correct
12 Correct 12 ms 48580 KB Output is correct
13 Correct 107 ms 49500 KB Output is correct
14 Correct 53 ms 49456 KB Output is correct
15 Correct 13 ms 49240 KB Output is correct
16 Correct 12 ms 49244 KB Output is correct
17 Execution timed out 2078 ms 136244 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 48476 KB Output is correct
2 Correct 12 ms 48372 KB Output is correct
3 Correct 11 ms 48476 KB Output is correct
4 Correct 12 ms 48568 KB Output is correct
5 Correct 11 ms 48476 KB Output is correct
6 Correct 11 ms 48372 KB Output is correct
7 Correct 12 ms 48472 KB Output is correct
8 Correct 12 ms 48476 KB Output is correct
9 Correct 11 ms 48476 KB Output is correct
10 Correct 12 ms 48592 KB Output is correct
11 Correct 12 ms 48472 KB Output is correct
12 Correct 11 ms 48476 KB Output is correct
13 Correct 11 ms 48476 KB Output is correct
14 Correct 11 ms 48476 KB Output is correct
15 Correct 78 ms 57428 KB Output is correct
16 Correct 77 ms 56916 KB Output is correct
17 Correct 80 ms 56912 KB Output is correct
18 Correct 84 ms 57172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48476 KB Output is correct
2 Correct 12 ms 48476 KB Output is correct
3 Correct 12 ms 48476 KB Output is correct
4 Correct 12 ms 48476 KB Output is correct
5 Correct 128 ms 136152 KB Output is correct
6 Correct 119 ms 136016 KB Output is correct
7 Correct 11 ms 48476 KB Output is correct
8 Correct 12 ms 48384 KB Output is correct
9 Correct 12 ms 48732 KB Output is correct
10 Correct 13 ms 48728 KB Output is correct
11 Correct 105 ms 73300 KB Output is correct
12 Correct 112 ms 64348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 48476 KB Output is correct
2 Correct 11 ms 48376 KB Output is correct
3 Correct 13 ms 48472 KB Output is correct
4 Correct 17 ms 48476 KB Output is correct
5 Correct 12 ms 48476 KB Output is correct
6 Correct 12 ms 48476 KB Output is correct
7 Correct 11 ms 48476 KB Output is correct
8 Correct 12 ms 48576 KB Output is correct
9 Correct 11 ms 48476 KB Output is correct
10 Correct 12 ms 48476 KB Output is correct
11 Correct 12 ms 48476 KB Output is correct
12 Correct 13 ms 48360 KB Output is correct
13 Correct 12 ms 48476 KB Output is correct
14 Correct 16 ms 48476 KB Output is correct
15 Correct 12 ms 48576 KB Output is correct
16 Correct 12 ms 48476 KB Output is correct
17 Correct 17 ms 48376 KB Output is correct
18 Correct 11 ms 48476 KB Output is correct
19 Correct 13 ms 48476 KB Output is correct
20 Correct 12 ms 48476 KB Output is correct
21 Correct 11 ms 48476 KB Output is correct
22 Correct 12 ms 48472 KB Output is correct
23 Correct 13 ms 48356 KB Output is correct
24 Correct 13 ms 48572 KB Output is correct
25 Correct 13 ms 48332 KB Output is correct
26 Correct 12 ms 48476 KB Output is correct
27 Correct 12 ms 48336 KB Output is correct
28 Correct 12 ms 48472 KB Output is correct
29 Correct 11 ms 48476 KB Output is correct
30 Correct 12 ms 48356 KB Output is correct
31 Correct 12 ms 48476 KB Output is correct
32 Correct 12 ms 48476 KB Output is correct
33 Correct 14 ms 48476 KB Output is correct
34 Correct 12 ms 48476 KB Output is correct
35 Correct 15 ms 48476 KB Output is correct
36 Correct 12 ms 48472 KB Output is correct
37 Correct 12 ms 48476 KB Output is correct
38 Correct 13 ms 48476 KB Output is correct
39 Correct 12 ms 48660 KB Output is correct
40 Correct 12 ms 48476 KB Output is correct
41 Correct 12 ms 48580 KB Output is correct
42 Correct 11 ms 48476 KB Output is correct
43 Correct 12 ms 48372 KB Output is correct
44 Correct 11 ms 48476 KB Output is correct
45 Correct 12 ms 48568 KB Output is correct
46 Correct 11 ms 48476 KB Output is correct
47 Correct 11 ms 48372 KB Output is correct
48 Correct 12 ms 48472 KB Output is correct
49 Correct 12 ms 48476 KB Output is correct
50 Correct 11 ms 48476 KB Output is correct
51 Correct 12 ms 48592 KB Output is correct
52 Correct 11 ms 48476 KB Output is correct
53 Correct 12 ms 48384 KB Output is correct
54 Correct 12 ms 48476 KB Output is correct
55 Incorrect 11 ms 48476 KB 2nd lines differ - on the 82nd token, expected: '0', found: '1'
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48476 KB Output is correct
2 Correct 12 ms 48476 KB Output is correct
3 Correct 12 ms 48476 KB Output is correct
4 Correct 12 ms 48476 KB Output is correct
5 Correct 13 ms 48360 KB Output is correct
6 Correct 12 ms 48476 KB Output is correct
7 Correct 16 ms 48476 KB Output is correct
8 Correct 12 ms 48576 KB Output is correct
9 Correct 12 ms 48476 KB Output is correct
10 Correct 17 ms 48376 KB Output is correct
11 Correct 11 ms 48476 KB Output is correct
12 Correct 13 ms 48476 KB Output is correct
13 Correct 12 ms 48476 KB Output is correct
14 Correct 11 ms 48476 KB Output is correct
15 Correct 12 ms 48472 KB Output is correct
16 Correct 13 ms 48356 KB Output is correct
17 Correct 13 ms 48572 KB Output is correct
18 Correct 13 ms 48332 KB Output is correct
19 Correct 12 ms 48476 KB Output is correct
20 Correct 12 ms 48336 KB Output is correct
21 Correct 12 ms 48472 KB Output is correct
22 Correct 11 ms 48476 KB Output is correct
23 Correct 12 ms 48356 KB Output is correct
24 Correct 12 ms 48476 KB Output is correct
25 Correct 95 ms 49492 KB Output is correct
26 Correct 58 ms 49500 KB Output is correct
27 Correct 38 ms 49500 KB Output is correct
28 Correct 12 ms 49240 KB Output is correct
29 Correct 94 ms 49488 KB Output is correct
30 Correct 20 ms 48988 KB Output is correct
31 Correct 14 ms 48728 KB Output is correct
32 Correct 13 ms 48732 KB Output is correct
33 Incorrect 14 ms 48848 KB 2nd lines differ - on the 524th token, expected: '0', found: '1'
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 48476 KB Output is correct
2 Correct 11 ms 48376 KB Output is correct
3 Correct 13 ms 48472 KB Output is correct
4 Correct 17 ms 48476 KB Output is correct
5 Correct 12 ms 48476 KB Output is correct
6 Correct 12 ms 48476 KB Output is correct
7 Correct 11 ms 48476 KB Output is correct
8 Correct 12 ms 48576 KB Output is correct
9 Correct 11 ms 48476 KB Output is correct
10 Correct 12 ms 48476 KB Output is correct
11 Correct 12 ms 48476 KB Output is correct
12 Correct 13 ms 48360 KB Output is correct
13 Correct 12 ms 48476 KB Output is correct
14 Correct 16 ms 48476 KB Output is correct
15 Correct 12 ms 48576 KB Output is correct
16 Correct 12 ms 48476 KB Output is correct
17 Correct 17 ms 48376 KB Output is correct
18 Correct 11 ms 48476 KB Output is correct
19 Correct 13 ms 48476 KB Output is correct
20 Correct 12 ms 48476 KB Output is correct
21 Correct 11 ms 48476 KB Output is correct
22 Correct 12 ms 48472 KB Output is correct
23 Correct 13 ms 48356 KB Output is correct
24 Correct 13 ms 48572 KB Output is correct
25 Correct 13 ms 48332 KB Output is correct
26 Correct 12 ms 48476 KB Output is correct
27 Correct 12 ms 48336 KB Output is correct
28 Correct 12 ms 48472 KB Output is correct
29 Correct 11 ms 48476 KB Output is correct
30 Correct 12 ms 48356 KB Output is correct
31 Correct 12 ms 48476 KB Output is correct
32 Correct 12 ms 48476 KB Output is correct
33 Correct 14 ms 48476 KB Output is correct
34 Correct 12 ms 48476 KB Output is correct
35 Correct 15 ms 48476 KB Output is correct
36 Correct 12 ms 48472 KB Output is correct
37 Correct 12 ms 48476 KB Output is correct
38 Correct 13 ms 48476 KB Output is correct
39 Correct 12 ms 48660 KB Output is correct
40 Correct 12 ms 48476 KB Output is correct
41 Correct 12 ms 48580 KB Output is correct
42 Correct 107 ms 49500 KB Output is correct
43 Correct 53 ms 49456 KB Output is correct
44 Correct 13 ms 49240 KB Output is correct
45 Correct 12 ms 49244 KB Output is correct
46 Correct 11 ms 48476 KB Output is correct
47 Correct 12 ms 48372 KB Output is correct
48 Correct 11 ms 48476 KB Output is correct
49 Correct 12 ms 48568 KB Output is correct
50 Correct 11 ms 48476 KB Output is correct
51 Correct 11 ms 48372 KB Output is correct
52 Correct 12 ms 48472 KB Output is correct
53 Correct 12 ms 48476 KB Output is correct
54 Correct 11 ms 48476 KB Output is correct
55 Correct 12 ms 48592 KB Output is correct
56 Correct 12 ms 48472 KB Output is correct
57 Correct 11 ms 48476 KB Output is correct
58 Correct 11 ms 48476 KB Output is correct
59 Correct 11 ms 48476 KB Output is correct
60 Correct 11 ms 48476 KB Output is correct
61 Correct 12 ms 48384 KB Output is correct
62 Correct 12 ms 48732 KB Output is correct
63 Correct 13 ms 48728 KB Output is correct
64 Correct 12 ms 48476 KB Output is correct
65 Incorrect 11 ms 48476 KB 2nd lines differ - on the 82nd token, expected: '0', found: '1'
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 48476 KB Output is correct
2 Correct 12 ms 48476 KB Output is correct
3 Correct 12 ms 48476 KB Output is correct
4 Correct 12 ms 48476 KB Output is correct
5 Correct 13 ms 48360 KB Output is correct
6 Correct 12 ms 48476 KB Output is correct
7 Correct 16 ms 48476 KB Output is correct
8 Correct 12 ms 48576 KB Output is correct
9 Correct 12 ms 48476 KB Output is correct
10 Correct 17 ms 48376 KB Output is correct
11 Correct 11 ms 48476 KB Output is correct
12 Correct 13 ms 48476 KB Output is correct
13 Correct 12 ms 48476 KB Output is correct
14 Correct 11 ms 48476 KB Output is correct
15 Correct 12 ms 48472 KB Output is correct
16 Correct 13 ms 48356 KB Output is correct
17 Correct 13 ms 48572 KB Output is correct
18 Correct 13 ms 48332 KB Output is correct
19 Correct 12 ms 48476 KB Output is correct
20 Correct 12 ms 48336 KB Output is correct
21 Correct 12 ms 48472 KB Output is correct
22 Correct 11 ms 48476 KB Output is correct
23 Correct 12 ms 48356 KB Output is correct
24 Correct 12 ms 48476 KB Output is correct
25 Correct 95 ms 49492 KB Output is correct
26 Correct 58 ms 49500 KB Output is correct
27 Correct 38 ms 49500 KB Output is correct
28 Correct 12 ms 49240 KB Output is correct
29 Correct 94 ms 49488 KB Output is correct
30 Correct 20 ms 48988 KB Output is correct
31 Correct 14 ms 48728 KB Output is correct
32 Correct 13 ms 48732 KB Output is correct
33 Incorrect 14 ms 48848 KB 2nd lines differ - on the 524th token, expected: '0', found: '1'
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 48476 KB Output is correct
2 Correct 11 ms 48376 KB Output is correct
3 Correct 13 ms 48472 KB Output is correct
4 Correct 17 ms 48476 KB Output is correct
5 Correct 12 ms 48476 KB Output is correct
6 Correct 12 ms 48476 KB Output is correct
7 Correct 11 ms 48476 KB Output is correct
8 Correct 12 ms 48576 KB Output is correct
9 Correct 11 ms 48476 KB Output is correct
10 Correct 12 ms 48476 KB Output is correct
11 Correct 12 ms 48476 KB Output is correct
12 Correct 13 ms 48360 KB Output is correct
13 Correct 12 ms 48476 KB Output is correct
14 Correct 16 ms 48476 KB Output is correct
15 Correct 12 ms 48576 KB Output is correct
16 Correct 12 ms 48476 KB Output is correct
17 Correct 17 ms 48376 KB Output is correct
18 Correct 11 ms 48476 KB Output is correct
19 Correct 13 ms 48476 KB Output is correct
20 Correct 12 ms 48476 KB Output is correct
21 Correct 11 ms 48476 KB Output is correct
22 Correct 12 ms 48472 KB Output is correct
23 Correct 13 ms 48356 KB Output is correct
24 Correct 13 ms 48572 KB Output is correct
25 Correct 13 ms 48332 KB Output is correct
26 Correct 12 ms 48476 KB Output is correct
27 Correct 12 ms 48336 KB Output is correct
28 Correct 12 ms 48472 KB Output is correct
29 Correct 11 ms 48476 KB Output is correct
30 Correct 12 ms 48356 KB Output is correct
31 Correct 12 ms 48476 KB Output is correct
32 Correct 12 ms 48476 KB Output is correct
33 Correct 14 ms 48476 KB Output is correct
34 Correct 12 ms 48476 KB Output is correct
35 Correct 15 ms 48476 KB Output is correct
36 Correct 12 ms 48472 KB Output is correct
37 Correct 12 ms 48476 KB Output is correct
38 Correct 128 ms 136152 KB Output is correct
39 Correct 119 ms 136016 KB Output is correct
40 Correct 13 ms 48476 KB Output is correct
41 Correct 12 ms 48660 KB Output is correct
42 Correct 12 ms 48476 KB Output is correct
43 Correct 12 ms 48580 KB Output is correct
44 Correct 107 ms 49500 KB Output is correct
45 Correct 53 ms 49456 KB Output is correct
46 Correct 13 ms 49240 KB Output is correct
47 Correct 12 ms 49244 KB Output is correct
48 Execution timed out 2078 ms 136244 KB Time limit exceeded
49 Halted 0 ms 0 KB -