답안 #984913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984913 2024-05-17T08:15:15 Z javotaz 사이버랜드 (APIO23_cyberland) C++17
컴파일 오류
0 ms 0 KB
using namespace std;

#pragma GCC optimize("Ofast,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")

typedef long long ll;
typedef pair<double, int> pd;

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()

const int N = 1e5 + 12, K = 76;
vector<pii> g[N];
int n, m, k, h, a[N];
double ans;
bool mrk[N][K], t[N]; 

void dfs(int u) {
	t[u] = true;
	if (u == h)
		return;
	for (auto i: g[u])
		if (!t[i.F])
			dfs(i.F);
}

void find_ans() {
	dfs(0);
	ans = 1e18;
	if (!t[h]) { 
		ans = -1;
		return;
	}
	priority_queue<pd, vector<pd>, greater<pd>> q;
	q.push({0, 0});
	for (int i = 1; i < n; i++)
		if (!a[i] && t[i])
			q.push({0, i});
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		int u = tmp.S % n, ck = tmp.S / n;
		double w = tmp.F;
		if (u == h) {
			ans = min(ans, w);
			mrk[u][ck] = true;
		}
		if (mrk[u][ck])
			continue;
		mrk[u][ck] = true;
		for (auto i: g[u])
			if (a[i.F] && !mrk[i.F][ck + (a[i.F] == 2)]) 
				if (a[i.F] == 1)
					q.push({w + i.S, i.F + ck * n});
				else if (ck + 1 <= k)
					q.push({(w + i.S) / 2.0, i.F + (ck + 1) * n});
	}
}

double solve(int ns, int ms, int ks, int hs, vector<int> xs, vector<int> ys, vector<int> ws, vector<int> as) {
	n = ns, m = ms, k = min(ks, 75), h = hs;
	for (int i = 0; i < m; i++)
		g[xs[i]].pb({ys[i], ws[i]}), g[ys[i]].pb({xs[i], ws[i]});
	for (int i = 0; i < n; i++)
		a[i] = as[i];
	find_ans();
	for (int i = 0; i < n; i++) {
		g[i].clear();
		t[i] = false;
		for (int j = 0; j <= k; ++j)
			mrk[i][j] = false;
	}
	return ans;
}

Compilation message

cyberland.cpp:7:9: error: 'pair' does not name a type
    7 | typedef pair<double, int> pd;
      |         ^~~~
cyberland.cpp:17:1: error: 'vector' does not name a type
   17 | vector<pii> g[N];
      | ^~~~~~
cyberland.cpp: In function 'void dfs(int)':
cyberland.cpp:26:15: error: 'g' was not declared in this scope
   26 |  for (auto i: g[u])
      |               ^
cyberland.cpp: In function 'void find_ans()':
cyberland.cpp:38:2: error: 'priority_queue' was not declared in this scope
   38 |  priority_queue<pd, vector<pd>, greater<pd>> q;
      |  ^~~~~~~~~~~~~~
cyberland.cpp:1:1: note: 'std::priority_queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
  +++ |+#include <queue>
    1 | using namespace std;
cyberland.cpp:38:17: error: 'pd' was not declared in this scope; did you mean 'pb'?
   38 |  priority_queue<pd, vector<pd>, greater<pd>> q;
      |                 ^~
      |                 pb
cyberland.cpp:38:21: error: 'vector' was not declared in this scope
   38 |  priority_queue<pd, vector<pd>, greater<pd>> q;
      |                     ^~~~~~
cyberland.cpp:1:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
  +++ |+#include <vector>
    1 | using namespace std;
cyberland.cpp:38:31: error: expected primary-expression before ',' token
   38 |  priority_queue<pd, vector<pd>, greater<pd>> q;
      |                               ^
cyberland.cpp:38:33: error: 'greater' was not declared in this scope
   38 |  priority_queue<pd, vector<pd>, greater<pd>> q;
      |                                 ^~~~~~~
cyberland.cpp:38:46: error: 'q' was not declared in this scope
   38 |  priority_queue<pd, vector<pd>, greater<pd>> q;
      |                                              ^
cyberland.cpp:49:10: error: 'min' was not declared in this scope
   49 |    ans = min(ans, w);
      |          ^~~
cyberland.cpp:50:11: error: 'ck' was not declared in this scope; did you mean 'k'?
   50 |    mrk[u][ck] = true;
      |           ^~
      |           k
cyberland.cpp:52:14: error: 'ck' was not declared in this scope; did you mean 'k'?
   52 |   if (mrk[u][ck])
      |              ^~
      |              k
cyberland.cpp:54:10: error: 'ck' was not declared in this scope; did you mean 'k'?
   54 |   mrk[u][ck] = true;
      |          ^~
      |          k
cyberland.cpp:55:16: error: 'g' was not declared in this scope
   55 |   for (auto i: g[u])
      |                ^
cyberland.cpp:56:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   56 |    if (a[i.F] && !mrk[i.F][ck + (a[i.F] == 2)])
      |       ^
cyberland.cpp: At global scope:
cyberland.cpp:64:46: error: 'vector' has not been declared
   64 | double solve(int ns, int ms, int ks, int hs, vector<int> xs, vector<int> ys, vector<int> ws, vector<int> as) {
      |                                              ^~~~~~
cyberland.cpp:64:52: error: expected ',' or '...' before '<' token
   64 | double solve(int ns, int ms, int ks, int hs, vector<int> xs, vector<int> ys, vector<int> ws, vector<int> as) {
      |                                                    ^
cyberland.cpp: In function 'double solve(int, int, int, int, int)':
cyberland.cpp:65:22: error: 'min' was not declared in this scope
   65 |  n = ns, m = ms, k = min(ks, 75), h = hs;
      |                      ^~~
cyberland.cpp:67:3: error: 'g' was not declared in this scope
   67 |   g[xs[i]].pb({ys[i], ws[i]}), g[ys[i]].pb({xs[i], ws[i]});
      |   ^
cyberland.cpp:67:5: error: 'xs' was not declared in this scope; did you mean 'ns'?
   67 |   g[xs[i]].pb({ys[i], ws[i]}), g[ys[i]].pb({xs[i], ws[i]});
      |     ^~
      |     ns
cyberland.cpp:67:16: error: 'ys' was not declared in this scope; did you mean 'ns'?
   67 |   g[xs[i]].pb({ys[i], ws[i]}), g[ys[i]].pb({xs[i], ws[i]});
      |                ^~
      |                ns
cyberland.cpp:67:23: error: 'ws' was not declared in this scope; did you mean 'ns'?
   67 |   g[xs[i]].pb({ys[i], ws[i]}), g[ys[i]].pb({xs[i], ws[i]});
      |                       ^~
      |                       ns
cyberland.cpp:69:10: error: 'as' was not declared in this scope; did you mean 'ns'?
   69 |   a[i] = as[i];
      |          ^~
      |          ns
cyberland.cpp:72:3: error: 'g' was not declared in this scope
   72 |   g[i].clear();
      |   ^