Submission #135463

# Submission time Handle Problem Language Result Execution time Memory
135463 2019-07-24T06:00:00 Z E869120 Two Transportations (JOI19_transportations) C++14
0 / 100
800 ms 23552 KB
#include "Azer.h"
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;

int NA, distA[2009]; bool usedA[2009];
vector<pair<int, int>> XA[2009];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> QA;

void pushesA(int pos, int val) {
	// 最初の 11 ビットは頂点、次の 20 ビットはコスト
	for (int i = 0; i < 11; i++) SendA((bool)((pos / (1 << i)) % 2));
	for (int i = 0; i < 20; i++) SendA((bool)((val / (1 << i)) % 2));
}

void InitA(int N, int A, std::vector<int> U, std::vector<int> V, std::vector<int> C) {
	NA = N;
	for (int i = 0; i < U.size(); i++) {
		XA[U[i]].push_back(make_pair(V[i], C[i]));
		XA[V[i]].push_back(make_pair(U[i], C[i]));
	}
	for (int i = 0; i < N; i++) distA[i] = (1 << 30);
	QA.push(make_pair(0, 0)); distA[0] = 0;

	vector<int> EA; EA.push_back(0);
	while (!QA.empty()) {
		int pos = QA.top().second; QA.pop();
		if (usedA[pos] == true) continue;
		usedA[pos] = true;

		for (int i = 0; i < XA[pos].size(); i++) {
			int to = XA[pos][i].first, cost = XA[pos][i].second;
			if (distA[to] > distA[pos] + cost) {
				distA[to] = distA[pos] + cost;
				QA.push(make_pair(distA[to], to));
				EA.push_back(to);
			}
		}
	}
	sort(EA.begin(), EA.end());
	EA.erase(unique(EA.begin(), EA.end()), EA.end());

	for (int i = 0; i < EA.size(); i++) {
		pushesA(EA[i], distA[EA[i]]);
	}
	pushesA((1 << 11) - 1, (1 << 20) - 1);
}

int countA = 0, VA = 0, LA = 0;

void ReceiveA(bool x) {
	if (countA < 31) {
		if (x == true) VA += (1 << countA);
		countA++;
	}
	if (countA == 31 && VA == 2147483647) {
		for (int i = 0; i < NA; i++) usedA[i] = false;

		vector<int> EA;
		while (!QA.empty()) {
			int pos = QA.top().second; QA.pop();
			if (usedA[pos] == true) continue;
			usedA[pos] = true;

			for (int i = 0; i < XA[pos].size(); i++) {
				int to = XA[pos][i].first, cost = XA[pos][i].second;
				if (distA[to] > distA[pos] + cost) {
					distA[to] = distA[pos] + cost;
					QA.push(make_pair(distA[to], to));
					EA.push_back(to);
				}
			}
		}
		sort(EA.begin(), EA.end());
		EA.erase(unique(EA.begin(), EA.end()), EA.end());

		for (int i = 0; i < EA.size(); i++) pushesA(EA[i], distA[EA[i]]);
		if (EA.size() >= 1 || LA >= 1) pushesA((1 << 11) - 1, (1 << 20) - 1);
		LA = 0;
	}
	if (countA == 31 && VA != 2147483647) {
		int pos = (VA & 1023), val = (VA >> 11);
		if (distA[pos] > val) {
			distA[pos] = val;
			QA.push(make_pair(distA[pos], pos));
		}
		LA++;
	}
	if (countA == 31) { countA = 0; VA = 0; }
}

vector<int> Answer() {
	vector<int>E;
	for (int i = 0; i < NA; i++) E.push_back(distA[i]);
	return E;
}
#include "Baijan.h"
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;

int NB, distB[2009]; bool usedB[2009];
vector<pair<int, int>> XB[2009];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> QB;

void pushesB(int pos, int val) {
	// 最初の 11 ビットは頂点、次の 20 ビットはコスト
	for (int i = 0; i < 11; i++) SendB((bool)((pos / (1 << i)) % 2));
	for (int i = 0; i < 20; i++) SendB((bool)((val / (1 << i)) % 2));
}

void InitB(int N, int B, vector<int> S, vector<int> T, vector<int> D) {
	NB = N;
	for (int i = 0; i < S.size(); i++) {
		XB[S[i]].push_back(make_pair(T[i], D[i]));
		XB[T[i]].push_back(make_pair(S[i], D[i]));
	}
	for (int i = 0; i < N; i++) distB[i] = (1 << 30);
}

int countB = 0, VB = 0;

void ReceiveB(bool y) {
	if (countB < 31) {
		if (y == true) VB += (1 << countB);
		countB++;
	}
	if (countB == 31 && VB == 2147483647) {
		for (int i = 0; i < NB; i++) usedB[i] = false;

		vector<int> EB;
		while (!QB.empty()) {
			int pos = QB.top().second; QB.pop();
			if (usedB[pos] == true) continue;
			usedB[pos] = true;

			for (int i = 0; i < XB[pos].size(); i++) {
				int to = XB[pos][i].first, cost = XB[pos][i].second;
				if (distB[to] > distB[pos] + cost) {
					distB[to] = distB[pos] + cost;
					QB.push(make_pair(distB[to], to));
					EB.push_back(to);
				}
			}
		}
		sort(EB.begin(), EB.end());
		EB.erase(unique(EB.begin(), EB.end()), EB.end());

		for (int i = 0; i < EB.size(); i++) pushesB(EB[i], distB[EB[i]]);
		pushesB((1 << 11) - 1, (1 << 20) - 1);
	}
	if (countB == 31 && VB != 2147483647) {
		int pos = (VB & 1023), val = (VB >> 11);
		if (distB[pos] > val) {
			distB[pos] = val;
			QB.push(make_pair(distB[pos], pos));
		}
	}
	if (countB == 31) { countB = 0; VB = 0; }
}

Compilation message

Azer.cpp: In function 'void InitA(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Azer.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < U.size(); i++) {
                  ~~^~~~~~~~~~
Azer.cpp:33:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < XA[pos].size(); i++) {
                   ~~^~~~~~~~~~~~~~~~
Azer.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < EA.size(); i++) {
                  ~~^~~~~~~~~~~
Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:67:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < XA[pos].size(); i++) {
                    ~~^~~~~~~~~~~~~~~~
Azer.cpp:79:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < EA.size(); i++) pushesA(EA[i], distA[EA[i]]);
                   ~~^~~~~~~~~~~

Baijan.cpp: In function 'void InitB(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Baijan.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < S.size(); i++) {
                  ~~^~~~~~~~~~
Baijan.cpp: In function 'void ReceiveB(bool)':
Baijan.cpp:43:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < XB[pos].size(); i++) {
                    ~~^~~~~~~~~~~~~~~~
Baijan.cpp:55:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < EB.size(); i++) pushesB(EB[i], distB[EB[i]]);
                   ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 752 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1208 KB Output is correct
2 Incorrect 74 ms 1760 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 437 ms 948 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 333 ms 1568 KB Output is correct
2 Correct 304 ms 1400 KB Output is correct
3 Correct 486 ms 23552 KB Output is correct
4 Correct 800 ms 1672 KB Output is correct
5 Incorrect 467 ms 8588 KB Wrong Answer [2]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 333 ms 1568 KB Output is correct
2 Correct 304 ms 1400 KB Output is correct
3 Correct 486 ms 23552 KB Output is correct
4 Correct 800 ms 1672 KB Output is correct
5 Incorrect 467 ms 8588 KB Wrong Answer [2]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 333 ms 1568 KB Output is correct
2 Correct 304 ms 1400 KB Output is correct
3 Correct 486 ms 23552 KB Output is correct
4 Correct 800 ms 1672 KB Output is correct
5 Incorrect 467 ms 8588 KB Wrong Answer [2]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 752 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -