# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
215909 | SamAnd | Fire drill (LMIO18_sauga) | C++17 | 1000 ms | 3064 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |