Submission #144257

# Submission time Handle Problem Language Result Execution time Memory
144257 2019-08-16T11:54:32 Z SamAnd Tenis (COI19_tenis) C++17
18 / 100
117 ms 2444 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1003;
struct ban
{
    int x, y, z;
};

int n, q;
ban a[N];

bool aa[N][N], bb[N][N];

int c[N];
vector<int> v;
void dfs(int x)
{
    c[x] = 1;
    for (int h = 1; h <= n; ++h)
    {
        if (aa[x][h] == true)
        {
            if (!c[h])
                dfs(h);
        }
    }
    v.push_back(x);
}

int k;
void dfs1(int x)
{
    c[x] = k;
    for (int h = 1; h <= n; ++h)
    {
        if (bb[x][h] == true)
        {
            if (!c[h])
                dfs1(h);
        }
    }
}

int qq;
bool cc[N];

void bil()
{
    memset(aa, false, sizeof aa);
    memset(bb, false, sizeof bb);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (a[i].x <= a[j].x || a[i].y <= a[j].y || a[i].z <= a[j].z)
            {
                aa[i][j] = true;
                bb[j][i] = true;
            }
        }
    }
    memset(c, 0, sizeof c);
    v.clear();
    for (int i = 1; i <= n; ++i)
    {
        if (c[i] == 0)
            dfs(i);
    }
    memset(c, 0, sizeof c);
    k = 0;
    reverse(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i)
    {
        int x = v[i];
        if (!c[x])
        {
            ++k;
            dfs1(x);
        }
    }
    memset(cc, false, sizeof cc);
    for (int x = 1; x <= n; ++x)
    {
        for (int y = 1; y <= n; ++y)
        {
            if (aa[x][y] == true)
            {
                if (c[x] == c[y])
                    continue;
                cc[c[y]] = true;
            }
        }
    }
    qq = 0;
    for (int i = 1; i <= k; ++i)
    {
        if (cc[i] == false)
            ++qq;
    }
}

int main()
{
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; ++i)
    {
        int x;
        scanf("%d", &x);
        a[x].x = i;
    }
    for (int i = 1; i <= n; ++i)
    {
        int x;
        scanf("%d", &x);
        a[x].y = i;
    }
    for (int i = 1; i <= n; ++i)
    {
        int x;
        scanf("%d", &x);
        a[x].z = i;
    }
    bil();
    while (q--)
    {
        int ty;
        scanf("%d", &ty);
        if (ty == 1)
        {
            int x;
            scanf("%d", &x);
            if (qq == 1 && cc[c[x]] == false)
                printf("DA\n");
            else
                printf("NE\n");
        }
        else
        {
            int p, x, y;
            scanf("%d%d%d", &p, &x, &y);
            if (p == 1)
                swap(a[x].x, a[y].x);
            else if (p == 2)
                swap(a[x].y, a[y].y);
            else
                swap(a[x].z, a[y].z);
            bil();
        }
    }
    return 0;
}

Compilation message

tenis.cpp: In function 'void bil()':
tenis.cpp:72:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
tenis.cpp: In function 'int main()':
tenis.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:108:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
tenis.cpp:114:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
tenis.cpp:120:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
tenis.cpp:127:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ty);
         ~~~~~^~~~~~~~~~~
tenis.cpp:131:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
tenis.cpp:140:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d", &p, &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 4 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 4 ms 2296 KB Output is correct
5 Correct 4 ms 2296 KB Output is correct
6 Correct 4 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 4 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 4 ms 2296 KB Output is correct
5 Correct 4 ms 2296 KB Output is correct
6 Correct 4 ms 2296 KB Output is correct
7 Correct 101 ms 2296 KB Output is correct
8 Correct 39 ms 2444 KB Output is correct
9 Correct 61 ms 2296 KB Output is correct
10 Correct 117 ms 2360 KB Output is correct
11 Correct 92 ms 2360 KB Output is correct
12 Correct 91 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 4 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 4 ms 2296 KB Output is correct
5 Correct 4 ms 2296 KB Output is correct
6 Correct 4 ms 2296 KB Output is correct
7 Correct 101 ms 2296 KB Output is correct
8 Correct 39 ms 2444 KB Output is correct
9 Correct 61 ms 2296 KB Output is correct
10 Correct 117 ms 2360 KB Output is correct
11 Correct 92 ms 2360 KB Output is correct
12 Correct 91 ms 2296 KB Output is correct
13 Runtime error 3 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 4 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 4 ms 2296 KB Output is correct
5 Correct 4 ms 2296 KB Output is correct
6 Correct 4 ms 2296 KB Output is correct
7 Correct 101 ms 2296 KB Output is correct
8 Correct 39 ms 2444 KB Output is correct
9 Correct 61 ms 2296 KB Output is correct
10 Correct 117 ms 2360 KB Output is correct
11 Correct 92 ms 2360 KB Output is correct
12 Correct 91 ms 2296 KB Output is correct
13 Runtime error 3 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -