# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103530 | phong | Bitaro’s Party (JOI18_bitaro) | C++17 | 2 ms | 5712 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<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define task "code"
const int ar = 1e5 + 5;
const ll mod = 1e9 + 7;
const int block = 100;
int n, m, q;
vector<int> ad[ar];
vector<pair<int, int>> lis[ar];
int x[ar];
bool check[ar];
int dp[ar];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n >> m >> q;
for (int i = 1; i <= m; i++)
{
int s, e;
cin >> s >> e;
ad[e].push_back(s);
}
for (int i = 1; i <= n; i++)
{
lis[i] = {{0, i}};
for (auto j : ad[i])
{
for (auto [w, u] : lis[j])
{
lis[i].push_back({w + 1, u});
}
}
sort(lis[i].begin(), lis[i].end(), greater<pair<int, int>>());
while(lis[i].size() > block) lis[i].pop_back();
}
while(q--)
{
int t, y;
cin >> t >> y;
for (int i = 1; i <= y; i++)
{
cin >> x[i];
check[x[i]] = true;
}
if (y >= block)
{
for (int i = 1; i <= t; i++)
{
dp[i] = 0;
for (auto j : ad[i])
{
if (check[j])
{
if (dp[j] > 0) dp[i] = max(dp[i], dp[j] + 1);
}
else dp[i] = max(dp[i], dp[j] + 1);
}
}
cout << dp[t] << '\n';
}
else
{
for (auto [w, u] : lis[t])
{
if (!check[u])
{
cout << w << '\n';
break;
}
}
}
for (int i = 1; i <= y; i++)
{
check[x[i]] = false;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |