| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 475847 | prvocislo | Bitaro’s Party (JOI18_bitaro) | C++17 | 765 ms | 168504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
const int maxn = 1e5 + 5, sq = 200;
int n, m, q, bad[maxn], dp[maxn];
vector<int> g[maxn];
vector<pair<int, int> > best[maxn];
void upd(int& a, const int& b) { a = max(a, b); }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> q;
for (int i = 0, a, b; i < m; i++)
{
cin >> a >> b;
g[--a].push_back(--b);
}
for (int i = 0; i < n; i++)
{
for (pair<int, int>& j : best[i]) j.first++;
if (best[i].size() < sq) best[i].push_back({ 0, i });
for (int j : g[i])
{
vector<pair<int, int> > v;
int pi = 0, pj = 0;
while (v.size() < sq && (pi < best[i].size() || pj < best[j].size()))
{
while (pi < best[i].size() && bad[best[i][pi].second]) pi++;
while (pj < best[j].size() && bad[best[j][pj].second]) pj++;
if (pi < best[i].size() && (pj == best[j].size() || best[i][pi].first > best[j][pj].first))
v.push_back(best[i][pi++]);
else if (pj < best[j].size())
v.push_back(best[j][pj++]);
}
for (pair<int, int> vi : v) bad[vi.second] = 0;
best[j] = v;
}
}
while (q--)
{
int u, s;
cin >> u >> s; u--;
vector<int> c(s);
for (int i = 0; i < s; i++)
{
cin >> c[i];
bad[--c[i]] = 1;
}
if (s > sq)
{
for (int i = 0; i < n; i++) dp[i] = -1e9;
for (int i = 0; i <= u; i++)
{
if (!bad[i]) upd(dp[i], 0);
for (int j : g[i]) upd(dp[j], dp[i] + 1);
}
cout << max(dp[u], -1) << "\n";
}
else
{
int ans = -1;
for (int i = 0; i < best[u].size(); i++) if (!bad[best[u][i].second])
{
ans = best[u][i].first;
break;
}
cout << ans << "\n";
}
for (int i = 0; i < s; i++) bad[c[i]] = 0;
}
return 0;
}Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
