QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#391551#3788. Funny Car Racingucup-team1251100 ✓105ms9160kbC++141.7kb2024-04-16 17:09:142024-04-16 17:09:14

Judging History

你现在查看的是最新测评结果

  • [2024-04-16 17:09:14]
  • 评测
  • 测评结果:100
  • 用时:105ms
  • 内存:9160kb
  • [2024-04-16 17:09:14]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
int dist[N];
struct stu
{
    int y, a, b, t;
};
vector<stu> g[N];
bool st[N];

void ffff(int root, int ende)
{
    memset(dist, 0x3f, sizeof dist);
    memset(st, false, sizeof st);
    dist[root] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.push({0, root});
    while (q.size())
    {
        auto t = q.top();
        q.pop();

        int Dist = t.first, id = t.second;
        if (st[id])
            continue;
        // cout << Dist << ' ' << id << '\n';
        st[id] = true;
        for (auto [y, a, b, t] : g[id])
        {
            if (t > a)
                continue;
            int u = Dist % (a + b);
            if (u + t <= a)
            {
                if (dist[y] > Dist + t)
                {
                    dist[y] = Dist + t;
                    q.push({dist[y], y});
                }
            }
            else
            {
                if (dist[y] > Dist + a + b - u + t)
                {
                    dist[y] = Dist + a + b - u + t;
                    q.push({dist[y], y});
                }
            }
            // int time_len = a + b;
            // int time_cnt = (Dist + time_len - 1) / time_len;
        }
    }
}

signed main()
{
    int Case = 0;
    int n, m, s, t;
    while (cin >> n >> m >> s >> t)
    {
        Case++;
        int u, v, a, b, tt;
        for (int i = 1; i <= n; i++)
            g[i].clear();
        for (int i = 1; i <= m; i++)
        {
            cin >> u >> v >> a >> b >> tt;
            g[u].push_back({v, a, b, tt});
        }
        ffff(s, t);
        cout << "Case " << Case << ": " << dist[t] << '\n';
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 105ms
memory: 9160kb

input:

155 9507 117 14
19 18 2 123 1
100 97 4 155 3
121 120 1 140 1
5 8 1 121 1
69 66 2 107 2
151 150 2 190 1
68 69 1 101 1
61 60 2 126 1
124 127 2 160 3
59 55 5 133 4
66 67 1 189 1
94 96 2 108 2
65 63 2 181 2
44 48 1 130 1
28 29 1 180 1
5 6 1 107 1
29 28 1 120 1
142 140 4 152 2
46 45 2 113 1
85 88 6 163 3...

output:

Case 1: 249
Case 2: 1540
Case 3: 1741
Case 4: 191
Case 5: 651
Case 6: 767
Case 7: 204
Case 8: 1016
Case 9: 582
Case 10: 248
Case 11: 323
Case 12: 322
Case 13: 1574
Case 14: 873
Case 15: 199
Case 16: 237
Case 17: 429
Case 18: 613
Case 19: 685
Case 20: 316
Case 21: 291
Case 22: 799
Case 23: 1009
Case ...

result:

ok 27 lines