Submission #409924

# Submission time Handle Problem Language Result Execution time Memory
409924 2021-05-21T19:15:41 Z mat_v Robot (JOI21_ho_t4) C++14
0 / 100
170 ms 17324 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<ll,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

struct edge{
    int x;
    int boja;
    ll v;
};
ll maks = 1e9;

int n,m;
vector<edge> graf[100005];
ll dist[100005];

bool cmp(edge a, edge b){
    if(a.boja < b.boja)return 1;
    return 0;
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);

    maks *= maks;
    cin >> n >> m;
    ff(i,1,m){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        graf[a].pb({b,c,d});
        graf[b].pb({a,c,d});
    }

    ff(i,1,n)sort(graf[i].begin(), graf[i].end(), cmp);

    priority_queue<pii> pq;

    ff(i,1,n)dist[i] = maks;
    dist[1] = 0;
    pq.push({0,1});
    while(!pq.empty()){
        pii sta = pq.top();
        pq.pop();
        int last = 0;
        ll sum = 0;
        int len = graf[sta.yy].size();
        if(len == 0)continue;
        ff(i,0,len - 1){
            if(graf[sta.yy][i].boja != graf[sta.yy][last].boja){
                ff(j,last,i-1){
                    ll duz = min(graf[sta.yy][j].v, sum - graf[sta.yy][j].v);
                    int koji = graf[sta.yy][j].x;
                    if(dist[koji] > duz - sta.xx){
                        dist[koji] = duz - sta.xx;
                        pq.push({-dist[koji], koji});
                    }
                }
                last = i;
                sum = graf[sta.yy][i].v;
            }
            else{
                sum += graf[sta.yy][i].v;
            }
        }
        ff(j,last,len-1){
            ll duz = min(graf[sta.yy][j].v, sum - graf[sta.yy][j].v);
            int koji = graf[sta.yy][j].x;
            if(dist[koji] > duz - sta.xx){
                dist[koji] = duz - sta.xx;
                pq.push({-dist[koji], koji});
            }
        }
    }
    if(dist[n] < maks)cout << dist[n] << "\n";
    else cout << -1 << "\n";


    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:45:5: note: in expansion of macro 'ff'
   45 |     ff(i,1,m){
      |     ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:52:5: note: in expansion of macro 'ff'
   52 |     ff(i,1,n)sort(graf[i].begin(), graf[i].end(), cmp);
      |     ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:56:5: note: in expansion of macro 'ff'
   56 |     ff(i,1,n)dist[i] = maks;
      |     ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:66:9: note: in expansion of macro 'ff'
   66 |         ff(i,0,len - 1){
      |         ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:68:17: note: in expansion of macro 'ff'
   68 |                 ff(j,last,i-1){
      |                 ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:83:9: note: in expansion of macro 'ff'
   83 |         ff(j,last,len-1){
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2680 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2676 KB Output is correct
5 Correct 2 ms 2676 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Incorrect 3 ms 2892 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 8776 KB Output is correct
2 Correct 26 ms 5408 KB Output is correct
3 Correct 81 ms 12716 KB Output is correct
4 Correct 42 ms 6932 KB Output is correct
5 Incorrect 170 ms 17324 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2680 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2676 KB Output is correct
5 Correct 2 ms 2676 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Incorrect 3 ms 2892 KB Output isn't correct
10 Halted 0 ms 0 KB -