#include <bits/stdc++.h>
#include "september.h"
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<ll, P>;
const ll n_ = 1e5 + 10, inf = (ll)2e9 * (ll)1e9 + 7, mod = 998244353;
ll n, m, tc = 1, a, b, c, d, sum, x, y, z, base, ans, k;
ll par[n_], mx[n_], L[n_], R[n_];
vector<ll> v[n_];
void dfs(ll x)
{
for (auto nxt : v[x])
{
dfs(nxt);
R[x] = max(R[x], R[nxt]);
}
}
int solve(int N, int M, vector<int> F, vector<vector<int>> S)
{
n = N - 1, m = M;
memset(par, -1, sizeof(par));
vector<ll> T;
for (int i = 0; i <= n; i++)
L[i] = inf, R[i] = -inf;
for (int j = 0; j < m; j++)
for (int i = 0; i < n; i++)
{
ll val = S[j][i];
L[val] = min(L[val], (ll)i);
R[val] = max(R[val], (ll)i);
}
for (int i = 1; i <= n; i++)
v[F[i]].push_back(i);
dfs(0);
vector<P> v;
for (int i = 1; i <= n; i++)
v.push_back({L[i], R[i]});
sort(all(v));
ll lim = -inf, ret = 0;
for (auto [a, b] : v)
{
if (lim < a)
{
ret++;
lim = b;
}
else
lim = max(lim, b);
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
3492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
3492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
3492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
3492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |