結果

提出番号 1983
提出者 eiya
言語 C++
提出日時 2018-08-04 14:49:44
問題名 (73)観光計画
結果 CE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 CE 0% 0ms 0KB
2 CE 0% 0ms 0KB
3 CE 0% 0ms 0KB
4 CE 0% 0ms 0KB
5 CE 0% 0ms 0KB
6 CE 0% 0ms 0KB
7 CE 0% 0ms 0KB
8 CE 0% 0ms 0KB
9 CE 0% 0ms 0KB
10 CE 0% 0ms 0KB
11 CE 0% 0ms 0KB
12 CE 0% 0ms 0KB
13 CE 0% 0ms 0KB
14 CE 0% 0ms 0KB
15 CE 0% 0ms 0KB
16 CE 0% 0ms 0KB
17 CE 0% 0ms 0KB
18 CE 0% 0ms 0KB
19 CE 0% 0ms 0KB
20 CE 0% 0ms 0KB
21 CE 0% 0ms 0KB
22 CE 0% 0ms 0KB
23 CE 0% 0ms 0KB
24 CE 0% 0ms 0KB
25 CE 0% 0ms 0KB
26 CE 0% 0ms 0KB
27 CE 0% 0ms 0KB
28 CE 0% 0ms 0KB
29 CE 0% 0ms 0KB
30 CE 0% 0ms 0KB
31 CE 0% 0ms 0KB
32 CE 0% 0ms 0KB
33 CE 0% 0ms 0KB
34 CE 0% 0ms 0KB
35 CE 0% 0ms 0KB
36 CE 0% 0ms 0KB
37 CE 0% 0ms 0KB
38 CE 0% 0ms 0KB
39 CE 0% 0ms 0KB
40 CE 0% 0ms 0KB
41 CE 0% 0ms 0KB
42 CE 0% 0ms 0KB
43 CE 0% 0ms 0KB
44 CE 0% 0ms 0KB
45 CE 0% 0ms 0KB
46 CE 0% 0ms 0KB
47 CE 0% 0ms 0KB
48 CE 0% 0ms 0KB
49 CE 0% 0ms 0KB
50 CE 0% 0ms 0KB
51 CE 0% 0ms 0KB
52 CE 0% 0ms 0KB
53 CE 0% 0ms 0KB
54 CE 0% 0ms 0KB
55 CE 0% 0ms 0KB
56 CE 0% 0ms 0KB
57 CE 0% 0ms 0KB
58 CE 0% 0ms 0KB
59 CE 0% 0ms 0KB
60 CE 0% 0ms 0KB
61 CE 0% 0ms 0KB
62 CE 0% 0ms 0KB
63 CE 0% 0ms 0KB
64 CE 0% 0ms 0KB
65 CE 0% 0ms 0KB
66 CE 0% 0ms 0KB
67 CE 0% 0ms 0KB
68 CE 0% 0ms 0KB
69 CE 0% 0ms 0KB
70 CE 0% 0ms 0KB

ソースコード




#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,M,K;


#include <queue>
#include <vector>
#include <functional>
#include <utility>
#include <algorithm>
#include <iterator>

using COST_T = uint64_t;
constexpr uint32_t N_MAX = 100100;
constexpr COST_T INF = 100000100000;//std::numeric_limits<double>::infinity()

#if defined(_MSC_VER) && defined(_DEBUG)
//static_assert(false, "リリースでコンパイルしないと遅いよ!!");
#endif

struct edge {
	uint32_t to;
	COST_T cost;
	edge() {}
	edge(uint32_t to_, COST_T cost_)
		:to(to_), cost(cost_) {}
};
std::vector<edge> graph[N_MAX];

//ダイクストラ
COST_T D[N_MAX];
void Dijkstra(uint32_t s)
{
	using P = std::pair<COST_T, uint32_t>;//cost pos
	std::priority_queue<P, std::vector<P>, std::greater<>> que;
	std::fill(std::begin(D), std::end(D), INF);

	D[s] = 0;
	que.emplace(0, s);
	while (!que.empty())
	{
		auto p = que.top(); que.pop();
		const auto& nowpos = p.second;
		const auto& nowcost = p.first;
		if (D[nowpos] < nowcost) { continue; }

		//for (int32_t to = 0; to < N; ++to)
		//{
		//	auto cost = nowcost + graph[nowpos][to];
		//	if (cost < D[to]) {
		//		D[to] = cost;
		//		que.emplace(D[to], to);
		//	}
		//}

		for (const auto& e : graph[nowpos])
		{
			auto cost = nowcost + e.cost;
			if (cost < D[e.to]) {
				D[e.to] = cost;
				que.emplace(cost, e.to);
			}
		}

	}
}



int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M>>K;

	for (int32_t i = 0; i < M; i++)
	{
		int32_t a, b, c;
		in >> a >> b >> c;

		graph[a].emplace_back(b, c);
		graph[b].emplace_back(a, c);

	}
	const COST_T INF2 = 100000;
	for (int32_t i = 0; i < K; i++)
	{
		int32_t a, c;
		in >> a >> c;

		graph[a].emplace_back(0, INF2 - c);
		graph[0].emplace_back(a, INF2 - c);
	}
	Dijkstra(0);
	int32_t res = 0;
	for (size_t i = 1; i <= N; i++)
	{
		if (D[i] <= INF2) {
			++res;
		}
	}
	out << res << endl;

	return 0;
}
#endif



#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


class Trie
{
private:
	int8_t just = 0;
	uint16_t child_num = 0;
	std::unique_ptr<Trie> childlen['z'-'a'+1];
public:

	void insert(const char* str) {
		++child_num;
		if (*str == '\0') { ++just; return; }
		if (childlen[*str - 'a'] == nullptr) { childlen[*str - 'a'] = std::make_unique<Trie>(); }
		childlen[*str - 'a']->insert(str + 1);
	}

	int32_t count(const char* str)const {
		if (*str == '\0') { return just; }
		if (*str == '*') { return child_num; }
		if (*str == '?') {
			int32_t res = 0;
			for (auto& i : childlen)
			{
				if(i){ res += i->count(str + 1); }
			}
			return res;
		}

		if (childlen[*str - 'a']) {
			return childlen[*str - 'a']->count(str + 1);
		}
		else {
			return 0;
		}
	}
};

int32_t N, M;
std::string buf;
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M;
	Trie trie;
	Trie trie_rev;
	buf.reserve(256);
	for (size_t i = 0; i < N; i++)
	{
		in >> buf;
		trie.insert(buf.c_str());
		std::reverse(buf.begin(), buf.end());
		trie_rev.insert(buf.c_str());
	}

	for (size_t i = 0; i < M; i++)
	{
		in >> buf;
		if (buf[0] == '*') {
			std::reverse(buf.begin(), buf.end());
			out << trie_rev.count(buf.c_str()) << endl;
		}
		else {
			out << trie.count(buf.c_str()) << endl;
		}
	}


	return 0;
}
#endif