# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1262808 | SmuggingSpun | Sirni (COCI17_sirni) | C++20 | 58 ms | 6580 KiB |
#include<bits/stdc++.h>
#define taskname "E"
using namespace std;
typedef long long ll;
int n;
namespace sub1{
void solve(){
vector<int>a(n);
for(int& x : a){
cin >> x;
}
vector<int>p(n);
iota(p.begin(), p.end(), 0);
auto find_set = [&] (int u){
while(u != p[u]){
u = p[u] = p[p[u]];
}
return u;
};
auto merge = [&] (int u, int v){
if((u = find_set(u)) != (v = find_set(v))){
p[u] = v;
return true;
}
return false;
};
vector<pair<int, pair<int, int>>>edge;
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
edge.emplace_back(make_pair(min(a[i] % a[j], a[j] % a[i]), make_pair(i, j)));
}
}
sort(edge.begin(), edge.end());
ll ans = 0;
for(auto& [w, e] : edge){
if(merge(e.first, e.second)){
ans += w;
}
}
cout << ans;
}
}
namespace sub23{
void solve(){
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n;
if(n <= 1000){
sub1::solve();
}
else{
sub23::solve();
}
}
컴파일 시 표준 에러 (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... |