Submission #289278

# Submission time Handle Problem Language Result Execution time Memory
289278 2020-09-02T14:01:38 Z SamAnd Toy Train (IOI17_train) C++17
16 / 100
25 ms 26112 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 5003;

int n;
vector<int> a, r;
vector<int> g[N];
bool u[N][N];
vector<int> rg[N];

vector<int> solv1()
{
    vector<int> ans(n);
    for (int i = n - 1; i >= 0; --i)
    {
        if (a[i])
        {
            if (r[i])
            {
                if (u[i][i])
                {
                    ans[i] = 1;
                }
                else
                {
                    ans[i] = ans[i + 1];
                }
            }
            else
            {
                if (u[i][i + 1])
                {
                    ans[i] = ans[i + 1];
                }
                else
                {
                    ans[i] = 0;
                }
            }
        }
        else
        {
            if (!r[i])
            {
                if (u[i][i])
                {
                    ans[i] = 0;
                }
                else
                {
                    ans[i] = ans[i + 1];
                }
            }
            else
            {
                if (u[i][i + 1])
                {
                    ans[i] = ans[i + 1];
                }
                else
                {
                    ans[i] = 1;
                }
            }
        }
    }
    return ans;
}

int c[N];
vector<int> v;
void dfs0(int x)
{
    c[x] = 1;
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        if (!c[h])
            dfs0(h);
    }
    v.push_back(x);
}

int k;
void dfs1(int x)
{
    c[x] = k;
    for (int i = 0; i < rg[x].size(); ++i)
    {
        int h = rg[x][i];
        if (!c[h])
            dfs1(h);
    }
}

vector<int> xg[N];
int q[N];
void kond()
{
    for (int x = 0; x < n; ++x)
    {
        if (!c[x])
            dfs0(x);
    }
    reverse(all(v));
    memset(c, 0, sizeof c);
    for (int i = 0; i < n; ++i)
    {
        int x = v[i];
        if (!c[x])
        {
            ++k;
            dfs1(x);
        }
    }

    for (int x = 0; x < n; ++x)
    {
        for (int i = 0; i < g[x].size(); ++i)
        {
            int y = g[x][i];
            if (c[x] != c[y])
            {
                xg[c[x]].push_back(c[y]);
            }
            else
                ++q[c[x]];
        }
    }
}

int ans[N];
bool cc[N];
bool uu[N];
void dfs3(int x)
{
    cc[x] = true;
    if (q[x] && uu[x])
        ans[x] = 1;
    for (int i = 0; i < xg[x].size(); ++i)
    {
        int h = xg[x][i];
        if (!cc[h])
            dfs3(h);
        if (ans[h])
            ans[x] = 1;
    }
}

vector<int> solv3()
{
    kond();
    for (int x = 0; x < n; ++x)
    {
        if (r[x])
            uu[c[x]] = true;
    }
    for (int i = 1; i <= k; ++i)
    {
        if (!cc[i])
        {
            dfs3(i);
        }
    }

    vector<int> ansv;
    for (int x = 0; x < n; ++x)
    {
        ansv.push_back(ans[c[x]]);
    }
    return ansv;
}

vector<int> solv4()
{
    return {};
}

std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> U, std::vector<int> V)
{
    a = A;
    r = R;

    n = sz(a);
    bool z1 = true;
    for (int i = 0; i < sz(U); ++i)
    {
        int x = U[i];
        int y = V[i];
        g[x].push_back(y);
        rg[y].push_back(x);
        u[x][y] = true;

        if (x != y && x + 1 != y)
            z1 = false;
    }

    bool z3 = true;
    bool z4 = true;
    for (int i = 0; i < n; ++i)
    {
        if (a[i])
        {
            z4 = false;
        }
        else
        {
            z3 = false;
        }
    }
    if (z3)
        return solv3();
    if (z1)
        return solv1();
}

Compilation message

train.cpp: In function 'void dfs0(int)':
train.cpp:82:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
train.cpp: In function 'void dfs1(int)':
train.cpp:95:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for (int i = 0; i < rg[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~~
train.cpp: In function 'void kond()':
train.cpp:126:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |         for (int i = 0; i < g[x].size(); ++i)
      |                         ~~^~~~~~~~~~~~~
train.cpp: In function 'void dfs3(int)':
train.cpp:147:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  147 |     for (int i = 0; i < xg[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:206:10: warning: variable 'z4' set but not used [-Wunused-but-set-variable]
  206 |     bool z4 = true;
      |          ^~
train.cpp:222:1: warning: control reaches end of non-void function [-Wreturn-type]
  222 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 15 ms 21376 KB Output is correct
2 Correct 15 ms 21376 KB Output is correct
3 Correct 15 ms 21376 KB Output is correct
4 Correct 16 ms 21376 KB Output is correct
5 Correct 15 ms 21376 KB Output is correct
6 Correct 15 ms 21376 KB Output is correct
7 Correct 16 ms 21376 KB Output is correct
8 Correct 16 ms 21632 KB Output is correct
9 Correct 15 ms 21376 KB Output is correct
10 Correct 15 ms 21376 KB Output is correct
11 Correct 14 ms 21376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 768 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 21504 KB Output is correct
2 Correct 21 ms 22400 KB Output is correct
3 Correct 21 ms 23416 KB Output is correct
4 Correct 24 ms 26112 KB Output is correct
5 Correct 24 ms 25848 KB Output is correct
6 Correct 24 ms 25720 KB Output is correct
7 Correct 25 ms 25208 KB Output is correct
8 Correct 22 ms 24056 KB Output is correct
9 Correct 21 ms 22908 KB Output is correct
10 Correct 22 ms 24320 KB Output is correct
11 Correct 23 ms 24192 KB Output is correct
12 Correct 24 ms 25600 KB Output is correct
13 Correct 25 ms 25848 KB Output is correct
14 Correct 25 ms 25856 KB Output is correct
15 Correct 24 ms 25856 KB Output is correct
16 Correct 25 ms 25856 KB Output is correct
17 Correct 24 ms 25976 KB Output is correct
18 Correct 21 ms 24832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 24696 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 25600 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 21376 KB Output is correct
2 Correct 15 ms 21376 KB Output is correct
3 Correct 15 ms 21376 KB Output is correct
4 Correct 16 ms 21376 KB Output is correct
5 Correct 15 ms 21376 KB Output is correct
6 Correct 15 ms 21376 KB Output is correct
7 Correct 16 ms 21376 KB Output is correct
8 Correct 16 ms 21632 KB Output is correct
9 Correct 15 ms 21376 KB Output is correct
10 Correct 15 ms 21376 KB Output is correct
11 Correct 14 ms 21376 KB Output is correct
12 Incorrect 1 ms 768 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
13 Halted 0 ms 0 KB -