Submission #990021

# Submission time Handle Problem Language Result Execution time Memory
990021 2024-05-29T11:18:16 Z Mihailo Cyberland (APIO23_cyberland) C++17
63 / 100
724 ms 16592 KB
#include "cyberland.h"
#include <cassert>
#include <cstdio>
#include <bits/stdc++.h>
#define pll pair<long long, long long>
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
using namespace std;
typedef long long ll;

vector<pair<__int128, long double> > adj[100100], v;
int a[100100], n, ks;
long double dis[100100], rez;

void dikstra() {
    priority_queue<pair<__int128, __int128> > q;
    pair<__int128, __int128> cur;
    for(int i=0; i<=n; i++) dis[i]=-1;
//    cout<<'\n';
    for(int j=0; j<v.size(); j++) {
        for(int i=0; i<adj[v[j].xx].size(); i++) {
            if(dis[adj[v[j].xx][i].xx]==-1) q.push(mp(v[j].yy-adj[v[j].xx][i].yy, adj[v[j].xx][i].xx));
        }
    }
    while(q.size()) {
        cur=q.top();
        q.pop();
//        cout<<cur.xx<<' '<<cur.yy<<'\n';
        if(dis[cur.yy]!=-1) continue;
        dis[cur.yy]=-cur.xx;
        for(int i=0; i<adj[cur.yy].size(); i++) {
            if(dis[adj[cur.yy][i].xx]==-1) q.push(mp(cur.xx-adj[cur.yy][i].yy, adj[cur.yy][i].xx));
        }
    }
}

double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
    K=min(100, K);
    for(int i=0; i<=N; i++) adj[i].clear();
    for(int i=0; i<M; i++) {
        adj[x[i]+1].pb(mp(y[i]+1, c[i]));
        adj[y[i]+1].pb(mp(x[i]+1, c[i]));
    }
    adj[H+1].clear();
    n=N;
    a[0]=1;
    a[1]=0;
    for(int i=1; i<arr.size(); i++) {
        a[i+1]=arr[i];
    }
    /////////
    adj[0].pb(mp(1, 0));
    v.clear();
    v.push_back(mp(0, 0));
    dikstra();
    if(dis[H+1]==-1) return -1;
    for(int i=1; i<=n; i++) {
        if(dis[i]==-1) a[i]=1;
    }
    adj[0].clear();
    /////////
    for(int i=1; i<=N; i++) {
        if(a[i]==0) adj[0].pb(mp(i, 0));
    }
    rez=1e30;
    ks=K;
    K++;
    while(K--) {
        dikstra();
        if(dis[H+1]>=0) rez=min(rez, dis[H+1]);
        v.clear();
        for(int i=1; i<=N; i++) {
            if(a[i]==2) v.pb(mp(i, -dis[i]/2));
        }
    }
    return rez;
}

Compilation message

cyberland.cpp: In function 'void dikstra()':
cyberland.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<__int128, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int j=0; j<v.size(); j++) {
      |                  ~^~~~~~~~~
cyberland.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<__int128, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for(int i=0; i<adj[v[j].xx].size(); i++) {
      |                      ~^~~~~~~~~~~~~~~~~~~~
cyberland.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<__int128, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int i=0; i<adj[cur.yy].size(); i++) {
      |                      ~^~~~~~~~~~~~~~~~~~~
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i=1; i<arr.size(); i++) {
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 4692 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4696 KB Correct.
2 Correct 27 ms 4700 KB Correct.
3 Correct 44 ms 4700 KB Correct.
4 Correct 45 ms 4700 KB Correct.
5 Correct 29 ms 4700 KB Correct.
6 Correct 29 ms 6232 KB Correct.
7 Correct 33 ms 5980 KB Correct.
8 Correct 15 ms 7260 KB Correct.
9 Correct 24 ms 4440 KB Correct.
10 Correct 40 ms 4444 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 32 ms 4700 KB Correct.
2 Correct 53 ms 4900 KB Correct.
3 Correct 30 ms 4948 KB Correct.
4 Correct 29 ms 4444 KB Correct.
5 Correct 29 ms 4440 KB Correct.
6 Correct 7 ms 6104 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 157 ms 12124 KB Correct.
2 Correct 184 ms 4700 KB Correct.
3 Correct 158 ms 4872 KB Correct.
4 Correct 164 ms 4700 KB Correct.
5 Correct 151 ms 4444 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4952 KB Correct.
2 Correct 24 ms 4956 KB Correct.
3 Correct 24 ms 4956 KB Correct.
4 Correct 34 ms 7348 KB Correct.
5 Correct 18 ms 4440 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 26 ms 4956 KB Correct.
2 Correct 22 ms 5168 KB Correct.
3 Correct 33 ms 14100 KB Correct.
4 Correct 19 ms 6700 KB Correct.
5 Correct 25 ms 4444 KB Correct.
6 Correct 25 ms 4952 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 250 ms 4944 KB Correct.
2 Correct 48 ms 5084 KB Correct.
3 Incorrect 367 ms 16592 KB Wrong Answer.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 623 ms 4948 KB Correct.
2 Correct 162 ms 5200 KB Correct.
3 Correct 724 ms 15712 KB Correct.
4 Incorrect 399 ms 8148 KB Wrong Answer.
5 Halted 0 ms 0 KB -