Submission #410248

# Submission time Handle Problem Language Result Execution time Memory
410248 2021-05-22T11:06:23 Z mat_v Robot (JOI21_ho_t4) C++14
24 / 100
298 ms 38648 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;

struct node{
    int cale;
    int x;
    ll v;
};

bool operator < (const node &a, const node &b){
    return a.v < b.v;
}
bool operator > (const node &a, const node &b){
    return a.v > b.v;
}

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

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

int main()
{

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

    maks *= maks;
    cin >> n >> m;
//    n = 1005;
//    m = 2005;
    ff(i,1,m){
        int a,b,c,d;
//        a = rnd()%n;
//        b = rnd()%n;
//        a++;
//        b++;
//        c = rnd()%m;
//        c++;
//        d = rnd()%1000000;
//        if(post[{a,b}]){
//            a = (rnd()%n) + 1;
//            b = (rnd()%n) + 1;
//        }
//        post[{a,b}] = post[{b,a}] = 1;
        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);
    ff(r,1,n){
        int len = graf[r].size();
        if(len == 0)continue;
        int last = 0;
        ll sum = 0;
        int koji = r;
        ff(i,0,len - 1){
            if(graf[koji][i].boja != graf[koji][last].boja){
                ff(j,last,i-1){
                    if(j < i-1){
                        int p1 = graf[koji][j].x;
                        int p2 = graf[koji][i - 1].x;
                        ll duz = sum - graf[koji][i - 1].v;
                        pravi[p1].pb({duz,p2});
                    }
                    else{
                        if(last != i-1){
                            int p1 = graf[koji][i - 1].x;
                            int p2 = graf[koji][i - 2].x;
                            ll duz = sum - graf[koji][i - 2].v;
                            pravi[p1].pb({duz,p2});
                        }
                    }
                    ll duz1 = graf[koji][j].v;
                    int gde = graf[koji][j].x;
                    duz1 = min(duz1, sum - graf[koji][j].v);
                    pravi[koji].pb({duz1,gde});
                }
                last = i;
                sum = graf[koji][i].v;
            }
            else{
                sum += graf[koji][i].v;
            }
        }
        ff(j,last,len-1){
            if(j < len-1){
                int p1 = graf[koji][j].x;
                int p2 = graf[koji][len - 1].x;
                ll duz = sum - graf[koji][len - 1].v;
                pravi[p1].pb({duz,p2});
            }
            else{
                if(last != len-1){
                    int p1 = graf[koji][len - 1].x;
                    int p2 = graf[koji][len - 2].x;
                    ll duz = sum - graf[koji][len - 2].v;
                    pravi[p1].pb({duz,p2});
                }
            }
            ll duz1 = graf[koji][j].v;
            int gde = graf[koji][j].x;
            duz1 = min(duz1, sum - graf[koji][j].v);
            pravi[koji].pb({duz1,gde});
        }
    }
    priority_queue<pii> pq;
    dist[1] = 0;
    ff(i,2,n)dist[i] = maks;
    pq.push({0,1});
    while(!pq.empty()){
        pii sta = pq.top();
        pq.pop();
        for(auto c:pravi[sta.yy]){
            int koji = c.yy;
            if(dist[koji] > c.xx - sta.xx){
                dist[koji] = c.xx - 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:62:5: note: in expansion of macro 'ff'
   62 |     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:81:5: note: in expansion of macro 'ff'
   81 |     ff(i,1,n)sort(graf[i].begin(), graf[i].end(), cmp);
      |     ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'r' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
Main.cpp:82:5: note: in expansion of macro 'ff'
   82 |     ff(r,1,n){
      |     ^~
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:88:9: note: in expansion of macro 'ff'
   88 |         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:90:17: note: in expansion of macro 'ff'
   90 |                 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:117:9: note: in expansion of macro 'ff'
  117 |         ff(j,last,len-1){
      |         ^~
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:140:5: note: in expansion of macro 'ff'
  140 |     ff(i,2,n)dist[i] = maks;
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 5024 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 3 ms 5028 KB Output is correct
7 Correct 4 ms 5068 KB Output is correct
8 Correct 4 ms 5068 KB Output is correct
9 Correct 5 ms 5196 KB Output is correct
10 Correct 5 ms 5320 KB Output is correct
11 Correct 5 ms 5296 KB Output is correct
12 Incorrect 5 ms 5292 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 88 ms 18544 KB Output is correct
2 Correct 38 ms 10848 KB Output is correct
3 Correct 127 ms 28552 KB Output is correct
4 Correct 64 ms 14104 KB Output is correct
5 Correct 220 ms 34728 KB Output is correct
6 Correct 217 ms 35928 KB Output is correct
7 Correct 217 ms 37080 KB Output is correct
8 Correct 298 ms 38588 KB Output is correct
9 Correct 291 ms 38648 KB Output is correct
10 Correct 150 ms 24692 KB Output is correct
11 Correct 111 ms 20788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 4 ms 5024 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 3 ms 5028 KB Output is correct
7 Correct 4 ms 5068 KB Output is correct
8 Correct 4 ms 5068 KB Output is correct
9 Correct 5 ms 5196 KB Output is correct
10 Correct 5 ms 5320 KB Output is correct
11 Correct 5 ms 5296 KB Output is correct
12 Incorrect 5 ms 5292 KB Output isn't correct
13 Halted 0 ms 0 KB -