제출 #532096

#제출 시각아이디문제언어결과실행 시간메모리
5320968e7Two Transportations (JOI19_transportations)C++17
컴파일 에러
0 ms0 KiB
#include "Azer.h"
#include <vector>
#include <iostream>
using namespace std;
#define ll long long
#define maxn 2005
#define pii pair<int, int>
#define ff first
#define ss second

namespace {
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif

const int inf = 1LL<<28;
const int wbit = 9, nbit = 12;
int N;
int done = 0;
int dis[maxn];
bool vis[maxn];
vector<pii> adj[maxn];

vector<bool> buf;
int wait = 0; //0:weight, 1:node

int cur = 0, bind = 0;

int uind = 0, uval = 0;


void send_weight(int w) {
	for (int i = 0;i < wbit;i++) {
		SendA(w & (1<<i));
	}
}
void send_node(int id) {
	for (int i = 0;i < nbit;i++) {
		SendA(id & (1<<i));
	}
}
int getnum() {
	int ret = 0;
	for (int i = 0;i < buf.size();i++) {
		ret = ret * 2 + (buf[i] ? 1 : 0);
	}
	buf.clear();
	return ret;
}
void get_best() {
	int best = inf;
	bind = 0;
	for (int j = 0;j < N;j++) {
		if (!vis[j] && dis[j] < best) {
			best = dis[j];
			bind = j;
		}
	}
	wait = 2;
	pary(vis, vis + N);
	debug("A best", bind, best - cur);
	send_weight(best - cur);
}
}  // namespace
std::vector<int> Answer() {
	std::vector<int> ans(N);
	for (int k = 0; k < N; ++k) {
		ans[k] = dis[k];
	}
	return ans;
}



void ReceiveA(bool x) {
	buf.push_back(x); 
	if (wait == 0 && buf.size() == wbit) {
		uval = getnum();
		wait = 1;
	} else if (wait == 1 && buf.size() == nbit){
		uind = getnum();
		dis[uind] = cur + uval;
		vis[uind] = 1;
		for (auto [v, e]:adj[uind]) {
			if (dis[uind] + e < dis[v]) {
				dis[v] = dis[uind] + e;
			}
		}
		cur += uval;
		if (++done >= N) Answer();
		else {
			debug(done);
			get_best();
		}
	} else {
		buf.clear();
		if (x) {
			wait = 0;
		} else {
			for (auto [v, e]:adj[bind]) {
				if (dis[bind] + e < dis[v]) {
					dis[v] = dis[bind] + e;
				}
			}
			vis[bind] = 1;
			cur = dis[bind];
			if (++done >= N) Answer();
			else {
				debug(done);
				send_node(bind);
				get_best();
			}
		}
	}
}

void InitA(int N, int A, std::vector<int> U, std::vector<int> V,
		std::vector<int> C) {
	::N = N;
	for (int i = 0; i < A; ++i) {
		adj[U[i]].push_back({V[i], C[i]});
		adj[V[i]].push_back({U[i], C[i]});
	}
	for (int i = 0;i < N;i++) dis[i] = inf;
	dis[0] = 0;
	get_best();	
}
	bind = 0;
	for (int j = 0;j < N;j++) {
		if (!vis[j] && dis[j] < best) {
			best = dis[j];
			bind = j;
		}
	}
	debug("B best", bind, best - cur, uval);
	if (best - cur < uval) {
		for (auto [v, e]:adj[bind]) {
			if (dis[bind] + e < dis[v]) {
				dis[v] = dis[bind] + e;
			}
		}
		vis[bind] = 1;
		cur = dis[bind];
		wait = 0;
		SendB(1);	
		send_weight(best - cur);
		send_node(bind);
	} else {
		wait = 1;
		SendB(0);
	}
}

}  // namespace
void ReceiveB(bool x) {
	buf.push_back(x); 
	if (wait == 0 && buf.size() == wbit) {
		uval = getnum();
		get_best();
		return;
	} else if (wait == 1 && buf.size() == nbit){
		uind = getnum();
		dis[uind] = cur + uval;
		vis[uind] = 1;
		for (auto [v, e]:adj[uind]) {
			if (dis[uind] + e < dis[v]) {
				dis[v] = dis[uind] + e;
			}
		}
		cur += uval;
		wait = 0;
	}
}

void InitB(int N, int A, std::vector<int> U, std::vector<int> V,
		std::vector<int> C) {
	::N = N;
	for (int i = 0; i < A; ++i) {
		adj[U[i]].push_back({V[i], C[i]});
		adj[V[i]].push_back({U[i], C[i]});
	}
	for (int i = 0;i < N;i++) dis[i] = inf;
	dis[0] = 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Azer.cpp: In function 'int {anonymous}::getnum()':
Azer.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0;i < buf.size();i++) {
      |                 ~~^~~~~~~~~~~~
Azer.cpp: In function 'void {anonymous}::get_best()':
Azer.cpp:21:19: warning: statement has no effect [-Wunused-value]
   21 | #define pary(...) 0
      |                   ^
Azer.cpp:68:2: note: in expansion of macro 'pary'
   68 |  pary(vis, vis + N);
      |  ^~~~
Azer.cpp:20:20: warning: statement has no effect [-Wunused-value]
   20 | #define debug(...) 0
      |                    ^
Azer.cpp:69:2: note: in expansion of macro 'debug'
   69 |  debug("A best", bind, best - cur);
      |  ^~~~~
Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:20:20: warning: statement has no effect [-Wunused-value]
   20 | #define debug(...) 0
      |                    ^
Azer.cpp:100:4: note: in expansion of macro 'debug'
  100 |    debug(done);
      |    ^~~~~
Azer.cpp:20:20: warning: statement has no effect [-Wunused-value]
   20 | #define debug(...) 0
      |                    ^
Azer.cpp:117:5: note: in expansion of macro 'debug'
  117 |     debug(done);
      |     ^~~~~

Baijan.cpp:1:2: error: 'bind' does not name a type
    1 |  bind = 0;
      |  ^~~~
Baijan.cpp:2:2: error: expected unqualified-id before 'for'
    2 |  for (int j = 0;j < N;j++) {
      |  ^~~
Baijan.cpp:2:17: error: 'j' does not name a type
    2 |  for (int j = 0;j < N;j++) {
      |                 ^
Baijan.cpp:2:23: error: 'j' does not name a type
    2 |  for (int j = 0;j < N;j++) {
      |                       ^
Baijan.cpp:8:7: error: expected constructor, destructor, or type conversion before '(' token
    8 |  debug("B best", bind, best - cur, uval);
      |       ^
Baijan.cpp:9:2: error: expected unqualified-id before 'if'
    9 |  if (best - cur < uval) {
      |  ^~
Baijan.cpp:21:4: error: expected unqualified-id before 'else'
   21 |  } else {
      |    ^~~~
Baijan.cpp:25:1: error: expected declaration before '}' token
   25 | }
      | ^
Baijan.cpp:27:1: error: expected declaration before '}' token
   27 | }  // namespace
      | ^
Baijan.cpp: In function 'void ReceiveB(bool)':
Baijan.cpp:29:2: error: 'buf' was not declared in this scope
   29 |  buf.push_back(x);
      |  ^~~
Baijan.cpp:30:6: error: 'wait' was not declared in this scope
   30 |  if (wait == 0 && buf.size() == wbit) {
      |      ^~~~
Baijan.cpp:30:33: error: 'wbit' was not declared in this scope
   30 |  if (wait == 0 && buf.size() == wbit) {
      |                                 ^~~~
Baijan.cpp:31:3: error: 'uval' was not declared in this scope
   31 |   uval = getnum();
      |   ^~~~
Baijan.cpp:31:10: error: 'getnum' was not declared in this scope; did you mean 'enum'?
   31 |   uval = getnum();
      |          ^~~~~~
      |          enum
Baijan.cpp:32:3: error: 'get_best' was not declared in this scope
   32 |   get_best();
      |   ^~~~~~~~
Baijan.cpp:34:40: error: 'nbit' was not declared in this scope
   34 |  } else if (wait == 1 && buf.size() == nbit){
      |                                        ^~~~
Baijan.cpp:35:3: error: 'uind' was not declared in this scope
   35 |   uind = getnum();
      |   ^~~~
Baijan.cpp:35:10: error: 'getnum' was not declared in this scope; did you mean 'enum'?
   35 |   uind = getnum();
      |          ^~~~~~
      |          enum
Baijan.cpp:36:3: error: 'dis' was not declared in this scope
   36 |   dis[uind] = cur + uval;
      |   ^~~
Baijan.cpp:36:15: error: 'cur' was not declared in this scope
   36 |   dis[uind] = cur + uval;
      |               ^~~
Baijan.cpp:36:21: error: 'uval' was not declared in this scope
   36 |   dis[uind] = cur + uval;
      |                     ^~~~
Baijan.cpp:37:3: error: 'vis' was not declared in this scope
   37 |   vis[uind] = 1;
      |   ^~~
Baijan.cpp:38:20: error: 'adj' was not declared in this scope
   38 |   for (auto [v, e]:adj[uind]) {
      |                    ^~~
Baijan.cpp: At global scope:
Baijan.cpp:48:26: error: 'std::vector' has not been declared
   48 | void InitB(int N, int A, std::vector<int> U, std::vector<int> V,
      |                          ^~~
Baijan.cpp:48:37: error: expected ',' or '...' before '<' token
   48 | void InitB(int N, int A, std::vector<int> U, std::vector<int> V,
      |                                     ^
Baijan.cpp: In function 'void InitB(int, int, int)':
Baijan.cpp:50:4: error: '::N' has not been declared
   50 |  ::N = N;
      |    ^
Baijan.cpp:52:3: error: 'adj' was not declared in this scope
   52 |   adj[U[i]].push_back({V[i], C[i]});
      |   ^~~
Baijan.cpp:52:7: error: 'U' was not declared in this scope
   52 |   adj[U[i]].push_back({V[i], C[i]});
      |       ^
Baijan.cpp:52:24: error: 'V' was not declared in this scope
   52 |   adj[U[i]].push_back({V[i], C[i]});
      |                        ^
Baijan.cpp:52:30: error: 'C' was not declared in this scope
   52 |   adj[U[i]].push_back({V[i], C[i]});
      |                              ^
Baijan.cpp:55:28: error: 'dis' was not declared in this scope
   55 |  for (int i = 0;i < N;i++) dis[i] = inf;
      |                            ^~~
Baijan.cpp:55:37: error: 'inf' was not declared in this scope; did you mean 'int'?
   55 |  for (int i = 0;i < N;i++) dis[i] = inf;
      |                                     ^~~
      |                                     int
Baijan.cpp:56:2: error: 'dis' was not declared in this scope
   56 |  dis[0] = 0;
      |  ^~~