제출 #215914

#제출 시각아이디문제언어결과실행 시간메모리
215914SamAndFire drill (LMIO18_sauga)C++17
43.73 / 100
1000 ms3060 KiB
#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] = v[i].second;
    }
    while (clock() / CLOCKS_PER_SEC < 0.8)
    {
        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) 메시지

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 timeMemoryGrader output
Fetching results...