Submission #112232

# Submission time Handle Problem Language Result Execution time Memory
112232 2019-05-18T00:44:36 Z ainta Two Transportations (JOI19_transportations) C++17
100 / 100
2132 ms 110832 KB
#include "Azer.h"
#include <vector>
#include <algorithm>

namespace AAA{
	int N, r1 = 0, r2 = 0;
	int w[2010][2010], D[2010], vis[2010];
	int count = 0, bef = 0, ccc = 0, cur = 0, cpv = 0;
	void Make(int num, int x) {
		if (num == 9)ccc++;
		int i;
		for (i = 0; i < num; i++) {
			SendA((x >> i) & 1);
		}
	}
	void Calc() {
		int i, Mn = 1e8, pv = -1, diff;
		for (i = 0; i < N; i++) {
			if (Mn > D[i] && !vis[i]) {
				Mn = D[i], pv = i;
			}
		}
		cur = Mn;
		cpv = pv;
		if (pv == -1) diff = 511, pv = 2047;
	}

	void receive(bool x) {
		int tt = x;
		count++;
		if (count <= 9) {
			r2 += (tt << (count-1));
		}
		if (count == 9) {
			Calc();
			if (bef + r2 >= cur) {
				Make(11, cpv);
				vis[cpv] = 1;
				count = 0;
				bef = cur;
				r1 = r2 = 0;
				if (ccc >= N)return;
				for (int i = 0; i < N; i++) {
					D[i] = std::min(D[i], D[cpv] + w[cpv][i]);
				}
				Calc();
				Make(9, std::min(cur - bef,511));
				return;
			}
		}
		if (count <= 9)return;
		r1 += (tt << (count - 10));
		if (count == 20) {
			D[r1] = std::min(D[r1], bef + r2);
			vis[r1] = 1;

			for (int i = 0; i < N; i++) {
				D[i] = std::min(D[i], D[r1] + w[r1][i]);
			}

			bef = bef + r2;
			count = 0;
			r1 = r2 = 0;
			if (ccc >= N)return;
			Calc();
			Make(9, std::min(cur - bef, 511));
			return;
		}
	}

	void init(int n, int A, std::vector<int> U, std::vector<int> V,
		std::vector<int> C) {

		N = n;
		for (int i = 0; i < N; i++) {
			D[i] = 1e9;
			vis[i] = 0;
			for (int j = 0; j < N; j++) {
				if (i != j)w[i][j] = 1e9;
				else w[i][j] = 0;
			}
		}
		D[0] = 0;
		for (int i = 0; i < U.size(); i++) {
			w[U[i]][V[i]] = std::min(w[U[i]][V[i]], C[i]);
			w[V[i]][U[i]] = std::min(w[V[i]][U[i]], C[i]);
		}
		Calc();
		Make(9, cur);
	}

	std::vector<int> answer() {
		std::vector<int> ans(N);
		for (int k = 0; k < N; ++k) {
			ans[k] = D[k];
		}
		return ans;
	}

}; // namespace

void InitA(int N, int A, std::vector<int> U, std::vector<int> V,
           std::vector<int> C) {

	AAA::init(N, A, U, V, C);
}

void ReceiveA(bool x) {
	AAA::receive(x);
}

std::vector<int> Answer() {
	return AAA::answer();
}
#include "Baijan.h"
#include <vector>
#include <algorithm>

namespace BBB{

	int N, r1 = 0, r2 = 0;
	int w[2010][2010], D[2010], vis[2010];
	int count = 0, bef = 0, ccc = 0, cur = 0, cpv = 0;
	void Make(int num, int x) {
		if (num == 9)ccc++;
		int i;
		for (i = 0; i < num; i++) {
			SendB((x >> i) & 1);
		}
	}
	void Calc() {
		int i, Mn = 1e8, pv = -1, diff;
		for (i = 0; i < N; i++) {
			if (Mn > D[i] && !vis[i]) {
				Mn = D[i], pv = i;
			}
		}
		cur = Mn;
		cpv = pv;
		if (pv == -1) diff = 511, pv = 2047;
	}

	void receive(bool y) {
		int tt = y;
		count++;
		if (count <= 9) {
			r2 += (tt << (count-1));
		}
		if (count == 9) {
			Calc();
			if (bef + r2 > cur) {
				Make(11, cpv);
				vis[cpv] = 1;
				count = 0;
				bef = cur;
				r1 = r2 = 0;
				if (ccc >= N)return;
				for (int i = 0; i < N; i++) {
					D[i] = std::min(D[i], D[cpv] + w[cpv][i]);
				}
				Calc();
				Make(9, std::min(cur - bef, 511));
				return;
			}
		}
		if (count <= 9)return;
		r1 += (tt << (count - 10));
		if (count == 20) {
			D[r1] = std::min(D[r1], bef + r2);
			vis[r1] = 1;

			for (int i = 0; i < N; i++) {
				D[i] = std::min(D[i], D[r1] + w[r1][i]);
			}

			bef = bef + r2;
			count = 0;
			r1 = r2 = 0;
			if (ccc >= N)return;
			Calc();
			Make(9, std::min(cur - bef,511));
			return;
		}
	}


	void init(int n, int A, std::vector<int> U, std::vector<int> V,
		std::vector<int> C) {

		N = n;
		for (int i = 0; i < N; i++) {
			D[i] = 1e9;
			vis[i] = 0;
			for (int j = 0; j < N; j++) {
				if (i != j)w[i][j] = 1e9;
				else w[i][j] = 0;
			}
		}
		D[0] = 0;
		for (int i = 0; i < U.size(); i++) {
			w[U[i]][V[i]] = std::min(w[U[i]][V[i]], C[i]);
			w[V[i]][U[i]] = std::min(w[V[i]][U[i]], C[i]);
		}
		Calc();
		Make(9, cur);
	}
}  // namespace

void InitB(int N, int B, std::vector<int> S, std::vector<int> T,
           std::vector<int> D) {
	BBB::init(N, B, S, T, D);
}

void ReceiveB(bool y) {
	BBB::receive(y);
}

Compilation message

Azer.cpp: In function 'void AAA::Calc()':
Azer.cpp:17:29: warning: variable 'diff' set but not used [-Wunused-but-set-variable]
   int i, Mn = 1e8, pv = -1, diff;
                             ^~~~
Azer.cpp: In function 'void AAA::init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Azer.cpp:84:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < U.size(); i++) {
                   ~~^~~~~~~~~~

Baijan.cpp: In function 'void BBB::Calc()':
Baijan.cpp:18:29: warning: variable 'diff' set but not used [-Wunused-but-set-variable]
   int i, Mn = 1e8, pv = -1, diff;
                             ^~~~
Baijan.cpp: In function 'void BBB::init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Baijan.cpp:86:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < U.size(); i++) {
                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1398 ms 64104 KB Output is correct
2 Correct 4 ms 1064 KB Output is correct
3 Correct 1258 ms 64448 KB Output is correct
4 Correct 1462 ms 78992 KB Output is correct
5 Correct 108 ms 3032 KB Output is correct
6 Correct 1282 ms 65880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 880 KB Output is correct
2 Correct 978 ms 64224 KB Output is correct
3 Correct 1236 ms 64576 KB Output is correct
4 Correct 1726 ms 99240 KB Output is correct
5 Correct 1800 ms 99312 KB Output is correct
6 Correct 192 ms 10208 KB Output is correct
7 Correct 1730 ms 99280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1085 ms 64216 KB Output is correct
2 Correct 8 ms 992 KB Output is correct
3 Correct 984 ms 64480 KB Output is correct
4 Correct 1306 ms 64120 KB Output is correct
5 Correct 1322 ms 64144 KB Output is correct
6 Correct 1594 ms 64288 KB Output is correct
7 Correct 1346 ms 64232 KB Output is correct
8 Correct 1212 ms 64144 KB Output is correct
9 Correct 981 ms 64224 KB Output is correct
10 Correct 1218 ms 64240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 488 ms 28128 KB Output is correct
2 Correct 506 ms 28216 KB Output is correct
3 Correct 748 ms 39144 KB Output is correct
4 Correct 568 ms 28480 KB Output is correct
5 Correct 719 ms 38056 KB Output is correct
6 Correct 512 ms 28080 KB Output is correct
7 Correct 591 ms 28128 KB Output is correct
8 Correct 550 ms 28392 KB Output is correct
9 Correct 848 ms 56800 KB Output is correct
10 Correct 814 ms 56560 KB Output is correct
11 Correct 998 ms 66360 KB Output is correct
12 Correct 908 ms 56424 KB Output is correct
13 Correct 538 ms 28128 KB Output is correct
14 Correct 8 ms 992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 488 ms 28128 KB Output is correct
2 Correct 506 ms 28216 KB Output is correct
3 Correct 748 ms 39144 KB Output is correct
4 Correct 568 ms 28480 KB Output is correct
5 Correct 719 ms 38056 KB Output is correct
6 Correct 512 ms 28080 KB Output is correct
7 Correct 591 ms 28128 KB Output is correct
8 Correct 550 ms 28392 KB Output is correct
9 Correct 848 ms 56800 KB Output is correct
10 Correct 814 ms 56560 KB Output is correct
11 Correct 998 ms 66360 KB Output is correct
12 Correct 908 ms 56424 KB Output is correct
13 Correct 538 ms 28128 KB Output is correct
14 Correct 8 ms 992 KB Output is correct
15 Correct 552 ms 36064 KB Output is correct
16 Correct 702 ms 36064 KB Output is correct
17 Correct 456 ms 35808 KB Output is correct
18 Correct 845 ms 45408 KB Output is correct
19 Correct 700 ms 35920 KB Output is correct
20 Correct 664 ms 45352 KB Output is correct
21 Correct 588 ms 36160 KB Output is correct
22 Correct 742 ms 35656 KB Output is correct
23 Correct 886 ms 70880 KB Output is correct
24 Correct 980 ms 70784 KB Output is correct
25 Correct 1332 ms 82696 KB Output is correct
26 Correct 1270 ms 68688 KB Output is correct
27 Correct 708 ms 35840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 488 ms 28128 KB Output is correct
2 Correct 506 ms 28216 KB Output is correct
3 Correct 748 ms 39144 KB Output is correct
4 Correct 568 ms 28480 KB Output is correct
5 Correct 719 ms 38056 KB Output is correct
6 Correct 512 ms 28080 KB Output is correct
7 Correct 591 ms 28128 KB Output is correct
8 Correct 550 ms 28392 KB Output is correct
9 Correct 848 ms 56800 KB Output is correct
10 Correct 814 ms 56560 KB Output is correct
11 Correct 998 ms 66360 KB Output is correct
12 Correct 908 ms 56424 KB Output is correct
13 Correct 538 ms 28128 KB Output is correct
14 Correct 8 ms 992 KB Output is correct
15 Correct 552 ms 36064 KB Output is correct
16 Correct 702 ms 36064 KB Output is correct
17 Correct 456 ms 35808 KB Output is correct
18 Correct 845 ms 45408 KB Output is correct
19 Correct 700 ms 35920 KB Output is correct
20 Correct 664 ms 45352 KB Output is correct
21 Correct 588 ms 36160 KB Output is correct
22 Correct 742 ms 35656 KB Output is correct
23 Correct 886 ms 70880 KB Output is correct
24 Correct 980 ms 70784 KB Output is correct
25 Correct 1332 ms 82696 KB Output is correct
26 Correct 1270 ms 68688 KB Output is correct
27 Correct 708 ms 35840 KB Output is correct
28 Correct 602 ms 45280 KB Output is correct
29 Correct 836 ms 45192 KB Output is correct
30 Correct 1146 ms 68624 KB Output is correct
31 Correct 790 ms 45096 KB Output is correct
32 Correct 1122 ms 62896 KB Output is correct
33 Correct 710 ms 45280 KB Output is correct
34 Correct 640 ms 45536 KB Output is correct
35 Correct 810 ms 45400 KB Output is correct
36 Correct 1268 ms 80584 KB Output is correct
37 Correct 1192 ms 80424 KB Output is correct
38 Correct 1378 ms 92384 KB Output is correct
39 Correct 1250 ms 82648 KB Output is correct
40 Correct 838 ms 45536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1398 ms 64104 KB Output is correct
2 Correct 4 ms 1064 KB Output is correct
3 Correct 1258 ms 64448 KB Output is correct
4 Correct 1462 ms 78992 KB Output is correct
5 Correct 108 ms 3032 KB Output is correct
6 Correct 1282 ms 65880 KB Output is correct
7 Correct 5 ms 880 KB Output is correct
8 Correct 978 ms 64224 KB Output is correct
9 Correct 1236 ms 64576 KB Output is correct
10 Correct 1726 ms 99240 KB Output is correct
11 Correct 1800 ms 99312 KB Output is correct
12 Correct 192 ms 10208 KB Output is correct
13 Correct 1730 ms 99280 KB Output is correct
14 Correct 1085 ms 64216 KB Output is correct
15 Correct 8 ms 992 KB Output is correct
16 Correct 984 ms 64480 KB Output is correct
17 Correct 1306 ms 64120 KB Output is correct
18 Correct 1322 ms 64144 KB Output is correct
19 Correct 1594 ms 64288 KB Output is correct
20 Correct 1346 ms 64232 KB Output is correct
21 Correct 1212 ms 64144 KB Output is correct
22 Correct 981 ms 64224 KB Output is correct
23 Correct 1218 ms 64240 KB Output is correct
24 Correct 488 ms 28128 KB Output is correct
25 Correct 506 ms 28216 KB Output is correct
26 Correct 748 ms 39144 KB Output is correct
27 Correct 568 ms 28480 KB Output is correct
28 Correct 719 ms 38056 KB Output is correct
29 Correct 512 ms 28080 KB Output is correct
30 Correct 591 ms 28128 KB Output is correct
31 Correct 550 ms 28392 KB Output is correct
32 Correct 848 ms 56800 KB Output is correct
33 Correct 814 ms 56560 KB Output is correct
34 Correct 998 ms 66360 KB Output is correct
35 Correct 908 ms 56424 KB Output is correct
36 Correct 538 ms 28128 KB Output is correct
37 Correct 8 ms 992 KB Output is correct
38 Correct 552 ms 36064 KB Output is correct
39 Correct 702 ms 36064 KB Output is correct
40 Correct 456 ms 35808 KB Output is correct
41 Correct 845 ms 45408 KB Output is correct
42 Correct 700 ms 35920 KB Output is correct
43 Correct 664 ms 45352 KB Output is correct
44 Correct 588 ms 36160 KB Output is correct
45 Correct 742 ms 35656 KB Output is correct
46 Correct 886 ms 70880 KB Output is correct
47 Correct 980 ms 70784 KB Output is correct
48 Correct 1332 ms 82696 KB Output is correct
49 Correct 1270 ms 68688 KB Output is correct
50 Correct 708 ms 35840 KB Output is correct
51 Correct 602 ms 45280 KB Output is correct
52 Correct 836 ms 45192 KB Output is correct
53 Correct 1146 ms 68624 KB Output is correct
54 Correct 790 ms 45096 KB Output is correct
55 Correct 1122 ms 62896 KB Output is correct
56 Correct 710 ms 45280 KB Output is correct
57 Correct 640 ms 45536 KB Output is correct
58 Correct 810 ms 45400 KB Output is correct
59 Correct 1268 ms 80584 KB Output is correct
60 Correct 1192 ms 80424 KB Output is correct
61 Correct 1378 ms 92384 KB Output is correct
62 Correct 1250 ms 82648 KB Output is correct
63 Correct 838 ms 45536 KB Output is correct
64 Correct 1292 ms 64576 KB Output is correct
65 Correct 1460 ms 88008 KB Output is correct
66 Correct 1850 ms 86608 KB Output is correct
67 Correct 1365 ms 64480 KB Output is correct
68 Correct 1000 ms 64592 KB Output is correct
69 Correct 2098 ms 110832 KB Output is correct
70 Correct 2132 ms 106320 KB Output is correct
71 Correct 1154 ms 68216 KB Output is correct
72 Correct 1206 ms 64640 KB Output is correct