답안 #888581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888581 2023-12-17T21:53:00 Z asdasdqwer Sirni (COCI17_sirni) C++14
0 / 140
5000 ms 786432 KB
#pragma GCC optimze("O3")
#pragma GCC target("avx,avx2,sse4")

#include <bits/stdc++.h>
using namespace std;

#define int int64_t

struct DSU {
    vector<int> p, r;
    DSU(int n) {
        p.assign(n,0);
        r.assign(n,0);
        for (int i=0;i<n;i++)p[i]=i;
    }

    int get(int i) {
        if (i != p[i]) p[i]=get(p[i]);
        return p[i];
    }

    bool unite(int a,int b) {
        a=get(a);
        b=get(b);
        if (a==b)return false;
        if (r[a]<r[b])swap(a,b);
        p[b]=a;
        if (r[a]==r[b])r[a]++;
        return true;
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;cin>>n;
    vector<int> a(n);
    for (int &x:a)cin>>x;
    sort(a.begin(),a.end());
    vector<int> b;
    for (int x:a) {
        if (b.size()==0||b.back()!=x)b.push_back(x);
    }

    if (b[0] == 1) {
        cout<<0<<"\n";
        return 0;
    }

    vector<bool> cont(b.back()+1, false);
    for (int x:b) {
        cont[x]=true;
    }

    vector<int> clos(b.back()+1,-1);
    for (int x:b) {
        clos[x]=x;
    }

    for (int i=1;i<clos.size();i++) {
        clos[i]=max(clos[i], clos[i-1]);
    }

    typedef array<int,3> pii;
    vector<pii> edg;
    for (int x:b) {
        vector<pii> tmp;
        for (int j=2*x;j<=b.back();j++) {
            if (clos[j] != -1) {
                if (!tmp.size()) {
                    tmp.push_back({clos[j] % x, clos[j], x});
                }

                else if (tmp.back()[1] != clos[j]) {
                    tmp.push_back({clos[j] % x, clos[j], x});
                }
            }
        }

        for (auto x:tmp) edg.push_back(x);
    }

    sort(edg.begin(),edg.end());
    map<int,int> mp;
    for (int i=0;i<b.size();i++) {
        mp[b[i]]=i;
    }

    for (auto &x:edg) {
        x[1]=mp[x[1]];
        x[2]=mp[x[2]];
    }

    DSU d(b.size());
    int cost=0;
    for (auto x:edg) {
        if (d.unite(x[1], x[2])) {
            cost+=x[0];
        }
    }
    cout<<cost<<"\n";
}

Compilation message

sirni.cpp:1: warning: ignoring '#pragma GCC optimze' [-Wunknown-pragmas]
    1 | #pragma GCC optimze("O3")
      | 
sirni.cpp: In function 'int main()':
sirni.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i=1;i<clos.size();i++) {
      |                  ~^~~~~~~~~~~~
sirni.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for (int i=0;i<b.size();i++) {
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3341 ms 87004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 7348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3365 ms 88184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 794 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1948 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 710 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 598 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2643 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2651 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5019 ms 278964 KB Time limit exceeded
2 Halted 0 ms 0 KB -