답안 #1106858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106858 2024-10-31T08:05:03 Z vjudge1 Sirni (COCI17_sirni) C++14
0 / 140
67 ms 79560 KB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
using namespace std;
using ll = long long;
const int nx=1e5+5;
int n, a[nx], par[nx];
ll ans=0;
vector<int> rar;
vector<pair<int, ii>> ed;
int find(int u)
{
    if(!par[u])
        return u;
    return par[u]=find(par[u]);
}
bool join(int u, int v)
{
    u=find(u);
    v=find(v);
    if(u==v)
        return 0;
    par[v]=u;
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i = 1; i <= n; i++)
        cin>>a[i], rar.emplace_back(a[i]);
    sort(rar.begin(), rar.end());
    rar.erase(unique(rar.begin(), rar.end()), rar.end());
    n=rar.size();
    vector<int> last(a[n] + 100, 0);
    for(int i = 1; i <= n; i++)
        a[i]=rar[i-1], last[a[i]]=i;
    for(int i = a[n] - 1; i >= 1; i--)
    {
        if(last[i])
            continue;
            last[i]=last[i+1];
    }
    for(int i = 1; i <= n; i++)
    {
        if(last[a[i]+1])
            ed.push_back({a[last[a[i]+1]]%a[i], {i, last[a[i]+1]}});
        for(int j = 2*a[i]; j < a[n]; j+=a[i])
            if(last[j])
                ed.push_back({a[last[j]]%a[i], {i, last[j]}});
    }
    sort(ed.begin(), ed.end());
    for(auto it:ed)
        if(join(it.se.fi, it.se.se))
            ans+=it.fi;
    cout<<ans;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:41:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   41 |         if(last[i])
      |         ^~
sirni.cpp:43:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   43 |             last[i]=last[i+1];
      |             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 40272 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 45 ms 69380 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 20 ms 9424 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3664 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 17 ms 6096 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 2004 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 65 ms 74956 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 67 ms 79560 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 33104 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -