Submission #215909

# Submission time Handle Problem Language Result Execution time Memory
215909 2020-03-26T12:23:28 Z SamAnd Fire drill (LMIO18_sauga) C++17
30.9806 / 100
1000 ms 3064 KB
#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

sauga.cpp: In function 'int main()':
sauga.cpp:42:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[x].size(); ++i)
                         ~~^~~~~~~~~~~~~
sauga.cpp:51:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[y].size(); ++i)
                         ~~^~~~~~~~~~~~~
sauga.cpp:63:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[x].size(); ++i)
                         ~~^~~~~~~~~~~~~
sauga.cpp:72:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[y].size(); ++i)
                         ~~^~~~~~~~~~~~~
sauga.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &tt, &n, &ss);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sauga.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &q);
         ~~~~~^~~~~~~~~~
sauga.cpp:25:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1000 ms 3064 KB Output isn't correct
2 Partially correct 1000 ms 504 KB Output is partially correct
3 Partially correct 1000 ms 504 KB Output is partially correct
4 Partially correct 1000 ms 384 KB Output is partially correct
5 Partially correct 1000 ms 504 KB Output is partially correct
6 Partially correct 1000 ms 448 KB Output is partially correct
7 Partially correct 1000 ms 888 KB Output is partially correct
8 Partially correct 1000 ms 2932 KB Output is partially correct
9 Partially correct 1000 ms 660 KB Output is partially correct
10 Partially correct 1000 ms 432 KB Output is partially correct