제출 #1325134

#제출 시각아이디문제언어결과실행 시간메모리
1325134luisdsSirni (COCI17_sirni)C++20
컴파일 에러
0 ms0 KiB
	#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::pair;
using std::vector;

int main() {
	int card_num;
	std::cin >> card_num;
	vector<int> cards(card_num);
	for (int &c : cards) {
		std::cin >> c;
		assert(c >= 1);
	}

	std::sort(cards.begin(), cards.end());
	// we can erase the dupes bc modding them with the original one = 0
	cards.erase(std::unique(cards.begin(), cards.end()), cards.end());

	int largest = cards.back();  // since we sorted the cards already
	// next_largest[i] contains the index of lowest card value that's >= i
	vector<int> next_largest(largest + 1, -1);
	for (int i = 0; i < cards.size(); i++) { next_largest[cards[i]] = i; }
	for (int c = largest - 1; c >= 0; c--) {
		// if this isn't assigned yet, assign it the previous one
		if (next_largest[c] == -1) { next_largest[c] = next_largest[c + 1]; }
	}

	vector<vector<pair<int, int>>> good_links(largest + 1);
	for (int i = 0; i < cards.size() - 1; i++) {
		// get all relevant cards this card could be connected to
		good_links[cards[i + 1] % cards[i]].push_back({i, i + 1});
		for (int at = 2 * cards[i]; at <= largest; at += cards[i]) {
			int good_mod = next_largest[at];
			good_links[cards[good_mod] % cards[i]].push_back({i, good_mod});
		}
	}

	long long total_cost = 0;
	DisjointSets linked_cards(cards.size());
	for (int c = 0; c <= largest; c++) {
		for (const pair<int, int> &link : good_links[c]) {
			bool result = linked_cards.unite(link.first, link.second);
			total_cost += c * result;
		}
	}

	cout << total_cost << endl;
}

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

sirni.cpp: In function 'int main()':
sirni.cpp:44:9: error: 'DisjointSets' was not declared in this scope
   44 |         DisjointSets linked_cards(cards.size());
      |         ^~~~~~~~~~~~
sirni.cpp:47:39: error: 'linked_cards' was not declared in this scope
   47 |                         bool result = linked_cards.unite(link.first, link.second);
      |                                       ^~~~~~~~~~~~