Submission #751532

#TimeUsernameProblemLanguageResultExecution timeMemory
751532somethingnewCyberland (APIO23_cyberland)C++17
Compilation error
0 ms0 KiB
#include <cassert> #include <cstdio> #include "queue" #include <vector> #include "iostream" using namespace std; vector<vector<pair<int, double>>> g; vector<int> slv1(vector<int> arr, int n, int k, int h) { priority_queue<pair<double, int>, vector<pair<double, int>>, greater<>> que; for (int i = 0; i < k; ++i) { que.push({0, i * n}); } vector<double> res(g.size(), 1e18); while (!que.empty()) { auto [prc, v] = que.top(); que.pop(); if (v % n == h) continue; if (1e17 > res[v]) continue; //cout << prc << ' ' << v << '\n'; res[v] = prc; for (auto i : g[v]) que.push({prc + i.second, i.first}); } vector<int> reska; for (int i = 0; i < g.size(); ++i) { if (res[i] < 1e17 and arr[i % n] == 0) reska.push_back(i); } return reska; } double slv2(int n, int k, int h, vector<int> tork) { priority_queue<pair<double, int>, vector<pair<double, int>>, greater<>> que; for (auto i : tork) { que.push({0, i}); } vector<double> res(g.size(), 1e18); //cerr << n * k - n + h << '\n'; while (!que.empty()) { auto [prc, v] = que.top(); que.pop(); if (1e17 > res[v]) continue; cout << prc << ' ' << v << '\n'; res[v] = prc; for (auto i : g[v]) que.push({prc + i.second, i.first}); } return res[n * k - n + h]; } double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { K = min(K, 30); int kn = K * N; //cout << kn << '\n'; g.assign(kn, {}); double dv = 1; for (int j = K - 1; j >= 0; --j) { for (int i = 0; i < M; ++i) { int a = x[i], b = y[i], tm = c[i]; int isa = arr[a]; a += j * N; b += j * N; g[a].push_back({b, tm / dv}); if (isa == 2) { if (j + 1 != K) g[a].push_back({b + N, tm * 2 / dv}); } a = y[i], b = x[i], tm = c[i]; isa = arr[a]; a += j * N; b += j * N; g[a].push_back({b, tm / dv}); if (isa == 2) { if (j + 1 != K) g[a].push_back({b + N, tm * 2 / dv}); } } dv *= 2; } arr[0] = 0; vector<int> tor2 = slv1(arr, N, K, H); for (auto i : tor2) cout << i << '\n'; double res = slv2(N, K, H, tor2); if (res > 1e17) return -1; return res; } int main() { int T; assert(1 == scanf("%d", &T)); while (T--){ int N,M,K,H; assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H)); std::vector<int> x(M); std::vector<int> y(M); std::vector<int> c(M); std::vector<int> arr(N); for (int i=0;i<N;i++) assert(1 == scanf("%d", &arr[i])); for (int i=0;i<M;i++) assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i])); printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr)); } } /* 1 3 3 1 2 1 2 1 0 1 60 1 2 30 0 2 70 */

Compilation message (stderr)

cyberland.cpp: In function 'std::vector<int> slv1(std::vector<int>, int, int, int)':
cyberland.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, double> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = 0; i < g.size(); ++i) {
      |                     ~~^~~~~~~~~~
/usr/bin/ld: /tmp/cco8KBk9.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc52b2p8.o:cyberland.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status