# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
679626 | as111 | Sirni (COCI17_sirni) | C++14 | 1546 ms | 543288 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#define MAXN 100000
#define MAXP 10000000
using namespace std;
typedef pair<int, int> pi;
int parent[MAXN + 5]; // initialize parent[i] = i
int findRoot(int a) {
return parent[a] = (parent[a] == a ? a : findRoot(parent[a]));
}
int join(int a, int b) {
a = findRoot(a);b = findRoot(b);
if (a == b) {
return 0;
}
parent[a] = b;
}
int N;
int Cards[MAXN + 5];
set<int> cards;
vector<pi> edges[MAXP + 5];; // PQ of edges
priority_queue<pair<int, pi>> PQ;
int card[MAXN + 5]; // value for each card ID
map<int, int> ID; // card value to card ID
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> Cards[i];
cards.insert(Cards[i]);
}
int i = 1;
for (int c : cards) {
ID[c] = i;
card[i] = c;
parent[i] = i;
i++;
}
int mx = 0;
for (int c : cards) {
/*
int s = i + 1;
for (int j = card[i]; j < MAXP; j += card[i])
{
while (s < cards.size() && card[s] < j) s++;
if (s < cards.size()) edges[card[s] % card[i]].emplace_back(i, s);
}*/
int mult = card[i]; // multiple
auto it = cards.lower_bound(mult);
while (it != cards.end()) {
if (*it - mult > c) mult += (*it - mult) / c * c; // c can be increased
mx = max(mx, *it - mult);
edges[*it - mult].emplace_back(ID[c], ID[*it]); // negative weight to go from least to greatest
mult += c;
it = cards.lower_bound(mult);
}
}
int ans = 0;
for (int p = 0; p <= mx;p++) {
for (auto curr : edges[p]) {
int f = curr.first;
int s = curr.second;
if (join(f, s))ans += p;
}
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |