Submission #976813

# Submission time Handle Problem Language Result Execution time Memory
976813 2024-05-07T06:54:53 Z rakhim_ova Cyberland (APIO23_cyberland) C++17
49 / 100
34 ms 10324 KB
#include "cyberland.h"
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
ll INF=1e13;
 
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) {
    int n=N, m=M, k=K, h=H;
    if(n<=3){
        if(h==0) return 0;
        vector<vector<double>> ct(n, vector<double> (n, -1));
        for(int i=0; i<m; i++){
            ct[x[i]][y[i]]=c[i];
            ct[y[i]][x[i]]=c[i];
        }
        double res=-1;
        if(ct[0][h]>=0){
            res=ct[0][h];
        }
        if(n<3) return res;
        if(ct[0][3-h]>=0 && ct[3-h][h]>=0){
            if(arr[3-h]==1){
                if(res<-0.5){
                    res=ct[0][3-h]+ct[3-h][h];
                }
                else{
                    res=min(res, ct[0][3-h]+ct[3-h][h]);
                }
            }
            else if(arr[3-h]==0){
                if(res<-0.5){
                    res=ct[3-h][h];
                }
                else{
                    res=min(res, ct[3-h][h]);
                }
            }
            else{
                if(k>0){
                    if(res<-0.5){
                        res=(double)ct[0][3-h]/2+ct[3-h][h];
                    }
                    else{
                        res=min(res, (double)ct[0][3-h]/2+ct[3-h][h]);
                    }
                }
                else{
                    if(res<-0.5){
                        res=ct[0][3-h]+ct[3-h][h];
                    }
                    else{
                        res=min(res, ct[0][3-h]+ct[3-h][h]);
                    }
                }
 
            }
        }
        return res;
    }
    double res=-1;
    vector<vector<pair<int, double>>> adj(n);
    for(int i=0; i<m; i++){
        adj[x[i]].push_back({y[i], c[i]});
        adj[y[i]].push_back({x[i], c[i]});
    }
    vector<double> d(n, INF);
    vector<bool> ch(n, false);
    priority_queue<pair<double, int>> pq;
    priority_queue<int> pq1;
 
    d[0]=0;
    pq1.push(0);
    while(!pq1.empty()){
        int t=pq1.top(); pq1.pop();
        if(ch[t] || t==h) continue;
        ch[t]=true;
        if(arr[t]==0){
            d[t]=0;
        }
        for(auto x: adj[t]){
            pq1.push(x.first);
        }
    }
    for(int i=0; i<n; i++){
        if(d[i]==0){
            pq.push({0, i});
            // cout << "-----\n";
        }
    }
    ch.clear();
    ch.resize(n, false);
    pq.push({0, 0});
    while(!pq.empty()){
        int t=pq.top().second; pq.pop();
        if(ch[t]) continue;
        ch[t]=true;
        for(auto x: adj[t]){
            if(d[t]+x.second<d[x.first]){
                // cout << t << ' ' << x.first << ' ' << d[t]+x.second << '\n';
                pq.push({-(d[t]+x.second), x.first});
                d[x.first]=d[t]+x.second;
            }
        }
    }
    if(d[h]==INF){
        return -1;
    }
    // for(auto x: d) cout << x << ' ';
    // cout << '\n';
    return d[h];
}

Compilation message

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:63:12: warning: unused variable 'res' [-Wunused-variable]
   63 |     double res=-1;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 824 KB Correct.
2 Correct 13 ms 860 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1360 KB Correct.
2 Correct 27 ms 1372 KB Correct.
3 Correct 25 ms 1372 KB Correct.
4 Correct 28 ms 1232 KB Correct.
5 Correct 27 ms 1372 KB Correct.
6 Correct 22 ms 2208 KB Correct.
7 Correct 30 ms 2232 KB Correct.
8 Correct 13 ms 3128 KB Correct.
9 Correct 25 ms 1116 KB Correct.
10 Correct 25 ms 1116 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1372 KB Correct.
2 Correct 29 ms 1360 KB Correct.
3 Correct 26 ms 1372 KB Correct.
4 Correct 32 ms 1332 KB Correct.
5 Correct 27 ms 1088 KB Correct.
6 Correct 5 ms 1628 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 8016 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1372 KB Correct.
2 Correct 26 ms 1124 KB Correct.
3 Correct 26 ms 1368 KB Correct.
4 Correct 29 ms 2384 KB Correct.
5 Correct 21 ms 1112 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1300 KB Correct.
2 Correct 25 ms 1372 KB Correct.
3 Correct 34 ms 10324 KB Correct.
4 Correct 16 ms 2228 KB Correct.
5 Correct 24 ms 1116 KB Correct.
6 Correct 26 ms 1372 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1360 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1364 KB Wrong Answer.
2 Halted 0 ms 0 KB -