Submission #202630

# Submission time Handle Problem Language Result Execution time Memory
202630 2020-02-17T11:29:37 Z SamAnd Olympic Bus (JOI20_ho_t4) C++17
5 / 100
1000 ms 8636 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 202, M = 50004;
const long long INF = 1000000009000000009;
struct ban0
{
    int x, y, c, d;
};

int n, m;
ban0 b[M];

struct ban
{
    int x;
    long long d;
    int z;
    int zn;
    ban(){}
    ban(int x, long long d, int z, int zn)
    {
        this->x = x;
        this->d = d;
        this->z = z;
        this->zn = zn;
    }
};
bool operator<(const ban& a, const ban& b)
{
    return a.d > b.d;
}

vector<ban> a[N];

bool c[N][2][2];

long long djk()
{
    for (int i = 1; i <= n; ++i)
        for (int j = 0; j < 2; ++j)
            for (int k = 0; k < 2; ++k)
                c[i][j][k] = false;
    priority_queue<ban> q;
    q.push(ban(1, 0, 0, 0));
    long long ans = INF;
    while (1)
    {
        ban t;
        do
        {
            if (q.empty())
            {
                return ans;
            }
            t = q.top();
            q.pop();
        } while (c[t.x][t.z][t.zn]);
        c[t.x][t.z][t.zn] = true;
        if (t.x == 1 && t.zn == 1)
            ans = min(ans, t.d);
        for (int i = 0; i < a[t.x].size(); ++i)
        {
            ban h = a[t.x][i];
            if (t.z && h.z)
                continue;
            h.d += t.d;
            h.z = (t.z | h.z);
            h.zn = (t.zn | h.zn);
            q.push(h);
        }
    }
}

void solv1()
{
    long long ans = INF;
    for (int j = 0; j <= m; ++j)
    {
        for (int i = 1; i <= n; ++i)
            a[i].clear();
        for (int i = 1; i <= m; ++i)
        {
            if (i == j)
            {
                if (b[i].x == n || b[i].y == n)
                {
                    a[b[i].y].push_back(ban(b[i].x, b[i].c, 0, 1));
                }
                else
                {
                    a[b[i].y].push_back(ban(b[i].x, b[i].c, 0, 0));
                }
                continue;
            }
            if (b[i].x == n || b[i].y == n)
            {
                a[b[i].x].push_back(ban(b[i].y, b[i].c, 0, 1));
            }
            else
            {
                a[b[i].x].push_back(ban(b[i].y, b[i].c, 0, 0));
            }
        }
        if (j == 0)
            ans = min(ans, djk());
        else
            ans = min(ans, djk() + b[j].d);
    }
    if (ans == INF)
        printf("-1\n");
    else
        printf("%lld\n", ans);
}

void solv2()
{
    for (int i = 1; i <= m; ++i)
    {
        if (b[i].x == n || b[i].y == n)
        {
            a[b[i].x].push_back(ban(b[i].y, b[i].c, 0, 1));
            a[b[i].y].push_back(ban(b[i].x, b[i].c + b[i].d, 1, 1));
        }
        else
        {
            a[b[i].x].push_back(ban(b[i].y, b[i].c, 0, 0));
            a[b[i].y].push_back(ban(b[i].x, b[i].c + b[i].d, 1, 0));
        }
    }
    long long ans = djk();
    if (ans == INF)
        printf("-1\n");
    else
        printf("%lld\n", ans);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; ++i)
    {
        scanf("%d%d%d%d", &b[i].x, &b[i].y, &b[i].c, &b[i].d);
    }
    solv1();
    return 0;
}

Compilation message

ho_t4.cpp: In function 'long long int djk()':
ho_t4.cpp:61:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[t.x].size(); ++i)
                         ~~^~~~~~~~~~~~~~~
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:140:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
ho_t4.cpp:143:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &b[i].x, &b[i].y, &b[i].c, &b[i].d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 124 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 254 ms 376 KB Output is correct
4 Correct 256 ms 376 KB Output is correct
5 Correct 274 ms 632 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 263 ms 504 KB Output is correct
10 Correct 259 ms 632 KB Output is correct
11 Correct 259 ms 504 KB Output is correct
12 Correct 256 ms 632 KB Output is correct
13 Correct 99 ms 380 KB Output is correct
14 Correct 181 ms 376 KB Output is correct
15 Correct 54 ms 376 KB Output is correct
16 Correct 182 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 8636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 504 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Execution timed out 1096 ms 6968 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 254 ms 376 KB Output is correct
4 Correct 256 ms 376 KB Output is correct
5 Correct 274 ms 632 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 263 ms 504 KB Output is correct
10 Correct 259 ms 632 KB Output is correct
11 Correct 259 ms 504 KB Output is correct
12 Correct 256 ms 632 KB Output is correct
13 Correct 99 ms 380 KB Output is correct
14 Correct 181 ms 376 KB Output is correct
15 Correct 54 ms 376 KB Output is correct
16 Correct 182 ms 376 KB Output is correct
17 Execution timed out 1092 ms 8636 KB Time limit exceeded
18 Halted 0 ms 0 KB -