Submission #112730

# Submission time Handle Problem Language Result Execution time Memory
112730 2019-05-21T16:17:15 Z Bruteforceman Two Transportations (JOI19_transportations) C++14
62 / 100
1844 ms 85552 KB
#include "Azer.h"
#include "bits/stdc++.h"
using namespace std;
 
namespace {
	struct node {
		int x;
		int dist;
		node () {}
		node (int x, int dist) : x(x), dist(dist) {}
		bool operator < (node n) const {
			return dist > n.dist;
		}
	};
	const int inf = 1000000000;
	const int sz = 11 + 9;
	int N;
	vector <int> buf;
	priority_queue <node> Q; 
	int last;
	vector <pair <int, int>> G[2005];
	bool done[2005];
	int d[2005];
 
	void sendInfo(int x, int value) {
		for(int i = 0; i < 11; i++) {
			SendA((x >> i) & 1);
		}
		for(int i = 11; i < sz; i++) {
			SendA((value >> (i - 11)) & 1);
		}
	}
	node getInfo(vector <int> v) {
		node ans (0, 0);
		for(int i = 0; i < 11; i++) {
			if(v[i]) {
				ans.x |= 1 << i;
			}
		}
		for(int i = 11; i < sz; i++) {
			if(v[i]) {
				ans.dist |= 1 << (i - 11);
			}
		}
		return ans;
	}
}  // namespace
 
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) {
    G[U[i]].push_back(pair <int, int> (V[i], C[i]));
    G[V[i]].push_back(pair <int, int> (U[i], C[i]));
  }
  last = 0;
  for(auto i : G[0]) {
  	Q.push(node(i.first, i.second));
  }
  for(int i = 0; i < N; i++) {
  	d[i] = inf;
  }
  d[0] = 0;
  done[0] = true;
  node init = Q.empty() ? node(N, 0) : Q.top();
  sendInfo(init.x, init.dist);
}
 
void ReceiveA(bool x) {
	bool good = true; 
	for(int i = 0; i < N; i++) {
		if(!done[i]) {
			good = false;
			break;
		}
	}
	if(good) return ;
	buf.push_back(x);
	if(buf.size() == sz) {
		while(!Q.empty() && done[Q.top().x]) {
			Q.pop();
		}
		node A = Q.empty() ? node(N, inf) : Q.top();
		node B = getInfo(buf);
		B.dist += last;
		if(B.x == N) B.dist = inf;
		node opt;
		if(A.dist > B.dist) {
			opt = B;
		} else {
			opt = A;
		}
		done[opt.x] = true;
		last = d[opt.x] = opt.dist;
 
		for(auto i : G[opt.x]) {
			if(d[opt.x] + i.second < d[i.first]) {
				d[i.first] = d[opt.x] + i.second;
				Q.push(node(i.first, d[i.first]));
			}
		}
		while(!Q.empty() && done[Q.top().x]) {
			Q.pop();
		}
		if(!Q.empty()) {
			node sender = Q.top();
			sendInfo(sender.x, sender.dist - last);
		} else {
			sendInfo(N, 0);
		}
		buf.clear();
	}
}
 
std::vector<int> Answer() {
	vector <int> ans;
	for(int i = 0; i < N; i++) {
		ans.push_back(d[i]);
	}
	return ans;
}

#include "Baijan.h"
#include "bits/stdc++.h"
using namespace std;
 
namespace {
	struct node {
		int x;
		int dist;
		node () {}
		node (int x, int dist) : x(x), dist(dist) {}
		bool operator < (node n) const {
			return dist > n.dist;
		}
	};
	const int inf = 1000000000;
	const int sz = 11 + 9;
	int N;
	vector <int> buf;
	priority_queue <node> Q; 
	int last;
	vector <pair <int, int>> G[2005];
	bool done[2005];
	int d[2005];
 
	void sendInfo(int x, int value) {
		for(int i = 0; i < 11; i++) {
			SendB((x >> i) & 1);
		}
		for(int i = 11; i < sz; i++) {
			SendB((value >> (i - 11)) & 1);
		}
	}
	node getInfo(vector <int> v) {
		node ans (0, 0);
		for(int i = 0; i < 11; i++) {
			if(v[i]) {
				ans.x |= 1 << i;
			}
		}
		for(int i = 11; i < sz; i++) {
			if(v[i]) {
				ans.dist |= 1 << (i - 11);
			}
		}
		return ans;
	}
}  // namespace
 
void InitB(int N, int B, std::vector<int> S, std::vector<int> T,
           std::vector<int> D) {
  ::N = N;
  for (int i = 0; i < B; ++i) {
    G[S[i]].push_back(pair <int, int> (T[i], D[i]));
    G[T[i]].push_back(pair <int, int> (S[i], D[i]));
  }
  last = 0;
  for(auto i : G[0]) {
  	Q.push(node(i.first, i.second));
  }
  for(int i = 0; i < N; i++) {
  	d[i] = inf;
  }
  d[0] = 0;
  done[0] = true;
}
 
void ReceiveB(bool x) {
	bool good = true; 
	for(int i = 0; i < N; i++) {
		if(!done[i]) {
			good = false;
			break;
		}
	}
	if(good) return ;
	buf.push_back(x);
	if(buf.size() == sz) {
		while(!Q.empty() && done[Q.top().x]) {
			Q.pop();
		}
		node A = Q.empty() ? node(N, inf) : Q.top();
		node B = getInfo(buf);
 
		B.dist += last;
		if(B.x == N) B.dist = inf;
		node opt;
		if(A.dist >= B.dist) {
			opt = B;
		} else {
			opt = A;
		}
		sendInfo(opt.x, opt.dist - last);
		done[opt.x] = true;
		last = d[opt.x] = opt.dist;
 
		for(auto i : G[opt.x]) {
			if(d[opt.x] + i.second < d[i.first]) {
				d[i.first] = d[opt.x] + i.second;
				Q.push(node(i.first, d[i.first]));
			}
		}
		buf.clear();
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 563 ms 944 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1248 KB Output is correct
2 Incorrect 466 ms 752 KB Wrong Answer [2]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 497 ms 756 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 599 ms 1520 KB Output is correct
2 Correct 658 ms 1512 KB Output is correct
3 Correct 560 ms 23520 KB Output is correct
4 Correct 708 ms 1504 KB Output is correct
5 Correct 748 ms 17192 KB Output is correct
6 Correct 680 ms 1512 KB Output is correct
7 Correct 552 ms 1760 KB Output is correct
8 Correct 714 ms 1760 KB Output is correct
9 Correct 914 ms 36024 KB Output is correct
10 Correct 1024 ms 35744 KB Output is correct
11 Correct 1236 ms 61176 KB Output is correct
12 Correct 1100 ms 53480 KB Output is correct
13 Correct 662 ms 1408 KB Output is correct
14 Correct 8 ms 1160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 599 ms 1520 KB Output is correct
2 Correct 658 ms 1512 KB Output is correct
3 Correct 560 ms 23520 KB Output is correct
4 Correct 708 ms 1504 KB Output is correct
5 Correct 748 ms 17192 KB Output is correct
6 Correct 680 ms 1512 KB Output is correct
7 Correct 552 ms 1760 KB Output is correct
8 Correct 714 ms 1760 KB Output is correct
9 Correct 914 ms 36024 KB Output is correct
10 Correct 1024 ms 35744 KB Output is correct
11 Correct 1236 ms 61176 KB Output is correct
12 Correct 1100 ms 53480 KB Output is correct
13 Correct 662 ms 1408 KB Output is correct
14 Correct 8 ms 1160 KB Output is correct
15 Correct 634 ms 1760 KB Output is correct
16 Correct 895 ms 1520 KB Output is correct
17 Correct 616 ms 1344 KB Output is correct
18 Correct 1046 ms 17552 KB Output is correct
19 Correct 798 ms 1600 KB Output is correct
20 Correct 1026 ms 18056 KB Output is correct
21 Correct 784 ms 1600 KB Output is correct
22 Correct 600 ms 1600 KB Output is correct
23 Correct 1052 ms 44168 KB Output is correct
24 Correct 1290 ms 43664 KB Output is correct
25 Correct 1584 ms 75088 KB Output is correct
26 Correct 1364 ms 64440 KB Output is correct
27 Correct 688 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 599 ms 1520 KB Output is correct
2 Correct 658 ms 1512 KB Output is correct
3 Correct 560 ms 23520 KB Output is correct
4 Correct 708 ms 1504 KB Output is correct
5 Correct 748 ms 17192 KB Output is correct
6 Correct 680 ms 1512 KB Output is correct
7 Correct 552 ms 1760 KB Output is correct
8 Correct 714 ms 1760 KB Output is correct
9 Correct 914 ms 36024 KB Output is correct
10 Correct 1024 ms 35744 KB Output is correct
11 Correct 1236 ms 61176 KB Output is correct
12 Correct 1100 ms 53480 KB Output is correct
13 Correct 662 ms 1408 KB Output is correct
14 Correct 8 ms 1160 KB Output is correct
15 Correct 634 ms 1760 KB Output is correct
16 Correct 895 ms 1520 KB Output is correct
17 Correct 616 ms 1344 KB Output is correct
18 Correct 1046 ms 17552 KB Output is correct
19 Correct 798 ms 1600 KB Output is correct
20 Correct 1026 ms 18056 KB Output is correct
21 Correct 784 ms 1600 KB Output is correct
22 Correct 600 ms 1600 KB Output is correct
23 Correct 1052 ms 44168 KB Output is correct
24 Correct 1290 ms 43664 KB Output is correct
25 Correct 1584 ms 75088 KB Output is correct
26 Correct 1364 ms 64440 KB Output is correct
27 Correct 688 ms 1656 KB Output is correct
28 Correct 978 ms 1504 KB Output is correct
29 Correct 936 ms 1488 KB Output is correct
30 Correct 1400 ms 42056 KB Output is correct
31 Correct 868 ms 1520 KB Output is correct
32 Correct 1166 ms 37288 KB Output is correct
33 Correct 990 ms 1632 KB Output is correct
34 Correct 842 ms 1760 KB Output is correct
35 Correct 754 ms 1640 KB Output is correct
36 Correct 1452 ms 49272 KB Output is correct
37 Correct 1292 ms 49088 KB Output is correct
38 Correct 1844 ms 85552 KB Output is correct
39 Correct 1800 ms 78480 KB Output is correct
40 Correct 908 ms 1544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 563 ms 944 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -