Submission #445868

# Submission time Handle Problem Language Result Execution time Memory
445868 2021-07-20T03:31:28 Z cpp219 Robot (JOI21_ho_t4) C++14
34 / 100
3000 ms 57900 KB
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e5 + 9;
const ll Log2 = 20;
const ll inf = 1e16 + 7;

map<LL,ll> mp,All;
vector<ll> d[N][2];

ll n,m,x,y,c,p,ans = inf;
struct Edge{
    ll to,c,p;
};
vector<Edge> g[N];

struct Node{
    ll val,i,change,prv;
};

bool operator < (Node a,Node b){
    return a.val > b.val;
}
priority_queue<Node> pq;

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        freopen(task".OUT","w",stdout);
    }
    cin>>n>>m;
    while(m--){
        cin>>x>>y>>c>>p;
        mp[{x,y}] = g[x].size(); mp[{y,x}] = g[y].size();
        g[x].push_back({y,c,p}); g[y].push_back({x,c,p});
    }
    for (ll i = 1;i <= n;i++){
        d[i][0].resize(g[i].size() + 3); d[i][1].resize(g[i].size() + 3);
        for (ll j = 0;j < d[i][0].size();j++){
            d[i][0][j] = d[i][1][j] = inf;
            if (i == 1) d[i][0][j] = d[i][1][j] = 0;
        }
        for (auto j : g[i]) All[{i,j.c}] += j.p;
    }
    pq.push({0,1,0,inf});
    while(!pq.empty()){
        //cout<<"?";
        Node t = pq.top(); pq.pop();
        ll u = t.i;
        if (u == n){
            ans = min(ans,t.val);
        }
        for (ll i = 0;i < g[u].size();i++){
            if (i == t.prv) continue;
            ll curC = g[u][i].c,v = g[u][i].to,L = g[u][i].p,change;
            ll cost = All[{u,curC}] - L;
            if (t.prv != inf && g[u][i].c == g[u][t.prv].c && t.change)
                cost -= g[u][t.prv].p;
            assert(t.change <= 1);
            //assert(cost >= 0);
            ll id = mp[{v,u}];
            if (d[v][0][id] > t.val + cost){
                d[v][0][id] = t.val + cost; //cout<<d[5][1][0]; return 0;
                //cout<<v<<" "<<1<<" "<<id<<" "<<t.val + cost<<"\n";
                pq.push({t.val + cost,v,0,id});
            }
            if (d[v][1][id] > t.val + L){
                d[v][1][id] = t.val + L; //cout<<d[5][1][0]; return 0;
                //cout<<v<<" "<<1<<" "<<id<<" "<<t.val + cost<<"\n";
                pq.push({t.val + L,v,1,id});
            }
        }
    }
    /// node   change   prv
    //cout<<g[2][1].to; return 0;
    //cout<<d[2][0][1]; return 0;
    if (ans != inf) cout<<ans;
    else cout<<-1;
}

Compilation message

Main.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
Main.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
Main.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
Main.cpp: In function 'int main()':
Main.cpp:49:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (ll j = 0;j < d[i][0].size();j++){
      |                       ~~^~~~~~~~~~~~~~~~
Main.cpp:63:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (ll i = 0;i < g[u].size();i++){
      |                       ~~^~~~~~~~~~~~~
Main.cpp:65:62: warning: unused variable 'change' [-Wunused-variable]
   65 |             ll curC = g[u][i].c,v = g[u][i].to,L = g[u][i].p,change;
      |                                                              ^~~~~~
Main.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(task".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7244 KB Output is correct
3 Correct 4 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 22 ms 7756 KB Output is correct
8 Correct 11 ms 7628 KB Output is correct
9 Correct 519 ms 8364 KB Output is correct
10 Correct 357 ms 8260 KB Output is correct
11 Correct 525 ms 8160 KB Output is correct
12 Correct 165 ms 8084 KB Output is correct
13 Correct 519 ms 8284 KB Output is correct
14 Correct 517 ms 8296 KB Output is correct
15 Correct 6 ms 7628 KB Output is correct
16 Correct 15 ms 7884 KB Output is correct
17 Correct 12 ms 8012 KB Output is correct
18 Correct 5 ms 7500 KB Output is correct
19 Correct 98 ms 8428 KB Output is correct
20 Correct 9 ms 7808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2104 ms 39380 KB Output is correct
2 Correct 620 ms 22704 KB Output is correct
3 Execution timed out 3080 ms 57900 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7244 KB Output is correct
2 Correct 4 ms 7244 KB Output is correct
3 Correct 4 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 22 ms 7756 KB Output is correct
8 Correct 11 ms 7628 KB Output is correct
9 Correct 519 ms 8364 KB Output is correct
10 Correct 357 ms 8260 KB Output is correct
11 Correct 525 ms 8160 KB Output is correct
12 Correct 165 ms 8084 KB Output is correct
13 Correct 519 ms 8284 KB Output is correct
14 Correct 517 ms 8296 KB Output is correct
15 Correct 6 ms 7628 KB Output is correct
16 Correct 15 ms 7884 KB Output is correct
17 Correct 12 ms 8012 KB Output is correct
18 Correct 5 ms 7500 KB Output is correct
19 Correct 98 ms 8428 KB Output is correct
20 Correct 9 ms 7808 KB Output is correct
21 Correct 2104 ms 39380 KB Output is correct
22 Correct 620 ms 22704 KB Output is correct
23 Execution timed out 3080 ms 57900 KB Time limit exceeded
24 Halted 0 ms 0 KB -