Submission #1048763

#TimeUsernameProblemLanguageResultExecution timeMemory
1048763PlurmSeptember (APIO24_september)C++17
100 / 100
155 ms19512 KiB
#include "september.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> g; vector<vector<int>> mxn; vector<vector<int>> bck; void dfs(int u){ for(int v : g[u]) dfs(v); for(int i = 0; i < bck.size(); i++){ mxn[i][u] = bck[i][u]; for(int v : g[u]){ mxn[i][u] = max(mxn[i][u], mxn[i][v]); } } } vector<int> rndperm; const int MOD = 1e9+7; class HashedSet{ public: int a, b, c, d, e; HashedSet() : a(0), b(1), c(0), d(1000000000), e(0) {} void insert(int x){ a += rndperm[x]; a %= MOD; b = 1ll * b * rndperm[x] % MOD; c = max(c, rndperm[x]); d = min(d, rndperm[x]); e ^= rndperm[x]; } friend bool operator!=(const HashedSet& h1, const HashedSet& h2){ return h1.a != h2.a || h1.b != h2.b || h1.c != h2.c || h1.d != h2.d || h1.e != h2.e; } }; int solve(int N, int M, vector<int> F, vector<vector<int>> S) { if(rndperm.empty()){ rndperm.resize(100005); default_random_engine dre; dre.seed(time(NULL)); uniform_int_distribution<int> uid(2, 1000000000); for(int i = 0; i <= 100000; i++) rndperm[i] = uid(dre); } g.resize(N); for(int i = 1; i < N; i++){ g[F[i]].push_back(i); } bck.resize(M); mxn.resize(M); for(int i = 0; i < M; i++){ bck[i].resize(N); mxn[i].resize(N); bck[i][0] = 0; for(int j = 0; j < N-1; j++){ bck[i][S[i][j]] = j; } } dfs(0); int k = 0; int l = 0; while(l < N-1){ // left: l vector<set<int>> ss(M); int mnr = l-1; int i = l; bool ok = true; do{ mnr++; if(mnr >= N-1) exit(-1); while(i <= mnr){ for(int j = 0; j < M; j++){ ss[j].insert(S[j][i]); mnr = max(mnr, mxn[j][S[j][i]]); } i++; } ok = true; for(int j = 1; j < M; j++) if(ss[j] != ss[0]) ok = false; }while(!ok); l = mnr+1; k++; } g.clear(); bck.clear(); mxn.clear(); return k; }

Compilation message (stderr)

september.cpp: In function 'void dfs(int)':
september.cpp:10:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i = 0; i < bck.size(); i++){
      |                    ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...