Submission #1227989

#TimeUsernameProblemLanguageResultExecution timeMemory
1227989peraCyberland (APIO23_cyberland)C++20
Compilation error
0 ms0 KiB
#include "cyberland.h"
#include <bits/stdc++.h>
#define LL long long
using namespace std;

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) {
   vector<vector<pair<int , LL>>> g(N);
   for(int i = 0;i < M;i ++){
      g[x[i]].emplace_back(y[i] , c[i]);
      g[y[i]].emplace_back(x[i] , c[i]);
   }
   K = min(K , 30);
   vector<vector<LL>> dist(N , vector<LL>(K + 1 , -1));
   priority_queue<tuple<LL , int , int> , vector<tuple<LL , int , int>> , greater<tuple<LL , int , int>>> pq;
   dist[H][0] = 0;
   pq.push(tuple<LL , int , int>{0 , H , 0});
   while(!pq.empty()){
      auto [D , u , x] = pq.top();
      pq.pop();
      for(auto [v , w] : g[u]){
         LL nD = D + w;
         if(arr[v] == 0){
            nD = 0;
         }
         if(dist[v][x] == -1 || dist[v][x] > nD){
            dist[v][x] = nD;
            pq.push(tuple<LL , int , int>{dist[v][x] , v , x});
         }
         if(arr[v] == 2 && x < K && (dist[v][x + 1] == -1 || dist[v][x + 1] > nD)){
            dist[v][x + 1] = nD;
            pq.push(tuple<LL , int , int>{dist[v][x + 1] , v , x});
         }
      }
   }
   LL ans = -1 , p = 0;
   for(int x = 0;x <= K;x ++){
      if(dist[0][x] != -1){
         if(ans == -1){
            ans = dist[0][x];
            p = x;
            continue;
         }
         LL left = ans * (1LL << x);
         LL right = dist[0][x] * (1LL << p);
         if(right < left){
            ans = dist[0][x];
            p = x;
         }
      }
   }
}
   if(ans == -1){
      return ans;
   }
   long double S = ans;
   for(int i = 0;i < p;i ++){
      S /= 2.0;
   }
   return (double)S;
}

Compilation message (stderr)

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:51:1: warning: no return statement in function returning non-void [-Wreturn-type]
   51 | }
      | ^
cyberland.cpp: At global scope:
cyberland.cpp:52:4: error: expected unqualified-id before 'if'
   52 |    if(ans == -1){
      |    ^~
cyberland.cpp:55:20: error: 'ans' was not declared in this scope; did you mean 'abs'?
   55 |    long double S = ans;
      |                    ^~~
      |                    abs
cyberland.cpp:56:4: error: expected unqualified-id before 'for'
   56 |    for(int i = 0;i < p;i ++){
      |    ^~~
cyberland.cpp:56:22: error: 'p' was not declared in this scope
   56 |    for(int i = 0;i < p;i ++){
      |                      ^
cyberland.cpp:56:22: error: 'p' was not declared in this scope
cyberland.cpp:56:22: error: 'p' was not declared in this scope
cyberland.cpp:56:22: error: 'p' was not declared in this scope
cyberland.cpp:56:22: error: 'p' was not declared in this scope
cyberland.cpp:56:22: error: 'p' was not declared in this scope
cyberland.cpp:56:22: error: 'p' was not declared in this scope
cyberland.cpp:56:22: error: 'p' was not declared in this scope
cyberland.cpp:56:22: error: 'p' was not declared in this scope
cyberland.cpp:56:18: error: 'i' does not name a type
   56 |    for(int i = 0;i < p;i ++){
      |                  ^
cyberland.cpp:56:24: error: 'i' does not name a type
   56 |    for(int i = 0;i < p;i ++){
      |                        ^
cyberland.cpp:59:4: error: expected unqualified-id before 'return'
   59 |    return (double)S;
      |    ^~~~~~
cyberland.cpp:60:1: error: expected declaration before '}' token
   60 | }
      | ^