# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
215909 | SamAnd | Fire drill (LMIO18_sauga) | C++17 | 1000 ms | 3064 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 m_p make_pair
const int N = 1003;
mt19937 rnd(3141);
int tt, n, ss;
vector<int> a[N];
vector<pair<int, int> > v;
int u[N];
int ans[N];
int main()
{
scanf("%d%d%d", &tt, &n, &ss);
for (int i = 1; i <= n; ++i)
{
int q;
scanf("%d", &q);
v.push_back(m_p(q, i));
while (q--)
{
int x;
scanf("%d", &x);
a[i].push_back(x);
}
}
sort(v.begin(), v.end());
for (int i = 0; i < n; ++i)
{
u[v[i].second] = i + 1;
ans[i + 1] = i + 1;
}
while (clock() / CLOCKS_PER_SEC < 0.9)
{
int x = rnd() % n + 1;
if (u[x] == n)
continue;
int y = ans[u[x] + 1];
bool z1 = false, z2 = false;
for (int i = 0; i < a[x].size(); ++i)
{
int h = a[x][i];
if (u[h] > u[x])
{
z1 = true;
break;
}
}
for (int i = 0; i < a[y].size(); ++i)
{
int h = a[y][i];
if (u[h] > u[y])
{
z2 = true;
break;
}
}
swap(ans[u[x]], ans[u[y]]);
swap(u[x], u[y]);
bool z11 = false, z21 = false;
for (int i = 0; i < a[x].size(); ++i)
{
int h = a[x][i];
if (u[h] > u[x])
{
z11 = true;
break;
}
}
for (int i = 0; i < a[y].size(); ++i)
{
int h = a[y][i];
if (u[h] > u[y])
{
z21 = true;
break;
}
}
if (z1 + z2 < z11 + z21)
{
swap(ans[u[x]], ans[u[y]]);
swap(u[x], u[y]);
}
}
for (int i = 1; i <= n; ++i)
printf("%d\n", ans[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |