Submission #583141

# Submission time Handle Problem Language Result Execution time Memory
583141 2022-06-24T22:09:30 Z NintsiChkhaidze Sirni (COCI17_sirni) C++14
112 / 140
5000 ms 435448 KB
#include <bits/stdc++.h>
//#include <iostream>
//#include <vector>
#define s second
#define pb push_back
#define f first
using namespace std;

const int N = 100005,M = 10000005;
int p[N],ans;
int m[M];

vector <pair<int,pair<int,int> > >  edges;
vector <pair<int,int> > d;

int P(int x){
    if (x == p[x]) return x;
    return p[x] = P(p[x]);
}

void dsu(int a,int b,int c){
    int pa = P(a),pb = P(b);
    if (pa == pb) return;
    ans += c;
    if (pa < pb) swap(pa,pb);
    p[pb] = pa;
}

int main() {
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin>>n;
    for (int i = 1; i <= n; i++){
        int a;
        cin>>a;
        p[i] = i;
        d.pb({a,i});
    }

    sort(d.begin(),d.end());
    int r = d.size() - 1;
    m[10000001] = -1;
    for (int i = 1e7; i >= 1; i--){
        m[i] = m[i + 1];
        while (r >= 0 && i <= d[r].f)
            m[i] = r--;
    }

    for (int y = 0; y < n; y++){
        if (y + 1 < n && d[y+1].f < 2*d[y].f)
            edges.pb({d[y+1].f - d[y].f,{y,y + 1}});

        if (y > 0 && d[y].f == d[y - 1].f) continue;
        for (int j = 2*d[y].f; j <= 1e7; j += d[y].f){
            if (m[j] < 0) continue;
            if (d[m[j]].f - j < d[y].f)
                edges.pb({d[m[j]].f - j,{y,m[j]}});
        }
    }

    sort(edges.begin(),edges.end());
    for (int i=0;i<edges.size();i++){
        int x = edges[i].s.f,y = edges[i].s.s,c = edges[i].f;
        dsu(x,y,c);
    }
    cout<<ans;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i=0;i<edges.size();i++){
      |                  ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 39592 KB Output is correct
2 Correct 88 ms 42672 KB Output is correct
3 Correct 41 ms 39740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 39544 KB Output is correct
2 Correct 301 ms 40264 KB Output is correct
3 Correct 45 ms 39756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 39584 KB Output is correct
2 Correct 39 ms 39388 KB Output is correct
3 Correct 40 ms 39560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 285 ms 53612 KB Output is correct
2 Correct 937 ms 90528 KB Output is correct
3 Correct 381 ms 65980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 42912 KB Output is correct
2 Correct 564 ms 90576 KB Output is correct
3 Correct 351 ms 65960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 596 ms 90692 KB Output is correct
2 Correct 1234 ms 139940 KB Output is correct
3 Correct 360 ms 66244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 46504 KB Output is correct
2 Correct 1171 ms 139836 KB Output is correct
3 Correct 343 ms 65996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 66036 KB Output is correct
2 Correct 4287 ms 435448 KB Output is correct
3 Correct 333 ms 66084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 65940 KB Output is correct
2 Execution timed out 5082 ms 435372 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 80 ms 42884 KB Output is correct
2 Execution timed out 5072 ms 435348 KB Time limit exceeded
3 Halted 0 ms 0 KB -