답안 #823838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823838 2023-08-13T08:25:16 Z hariaakas646 Robot (JOI21_ho_t4) C++17
0 / 100
506 ms 80752 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

int main()
{
    int n, m;
    scd(n);
    scd(m);
    vector<vector<pair<pii, int>>> graph(n + 1);
    vector<map<int, mseti>> cnt(n + 1);

    frange(i, m)
    {
        int a, b, c, p;
        scd(a);
        scd(b);
        scd(c);
        scd(p);
        graph[a].pb(mp(mp(b, p), c));
        graph[b].pb(mp(mp(a, p), c));
        cnt[a][c].insert(p);
        cnt[b][c].insert(p);
    }
    vector<map<int, lli>> val(n + 1);

    forr(i, 1, n + 1)
    {
        for (auto p : cnt[i])
        {
            int x = p.f;
            int c = p.s.size();
            auto it = p.s.begin();
            frange(j, c - 1)
            {
                val[i][x] += *it;
                it++;
            }
            // printf("%lld ", val[i][x]);
        }
        // printf("\n");
    }

    vll dist(n + 1, 1e18);
    dist[1] = 0;
    priority_queue<pair<lli, int>> pq;
    vb vis(n + 1);
    pq.push(mp(0, 1));

    while (pq.size())
    {
        auto p = pq.top();
        pq.pop();
        if (vis[p.s])
            continue;
        vis[p.s] = true;

        for (auto e : graph[p.s])
        {
            if (dist[p.s] + min(lli(e.f.s), val[p.s][e.s]) < dist[e.f.f])
            {
                dist[e.f.f] = dist[p.s] + min(lli(e.f.s), val[p.s][e.s]);
                pq.push(mp(-dist[e.f.f], e.f.f));
            }
        }
    }
    if (dist[n] == 1e18)
        printf("-1");
    else
        printf("%lld", dist[n]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:30:5: note: in expansion of macro 'scd'
   30 |     scd(n);
      |     ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:31:5: note: in expansion of macro 'scd'
   31 |     scd(m);
      |     ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:38:9: note: in expansion of macro 'scd'
   38 |         scd(a);
      |         ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:39:9: note: in expansion of macro 'scd'
   39 |         scd(b);
      |         ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:40:9: note: in expansion of macro 'scd'
   40 |         scd(c);
      |         ^~~
Main.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
Main.cpp:41:9: note: in expansion of macro 'scd'
   41 |         scd(p);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 2 ms 1080 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 26180 KB Output is correct
2 Correct 38 ms 13288 KB Output is correct
3 Correct 183 ms 28156 KB Output is correct
4 Correct 61 ms 18380 KB Output is correct
5 Incorrect 506 ms 80752 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 2 ms 1080 KB Output isn't correct
10 Halted 0 ms 0 KB -