Submission #582377

# Submission time Handle Problem Language Result Execution time Memory
582377 2022-06-23T17:03:06 Z mosiashvililuka Sirni (COCI17_sirni) C++14
112 / 140
5000 ms 438492 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,f[100009],pas,msh[100009],zm[100009],fx[10000009];
vector <pair <int, pair <int, int> > > P;
int fnd(int q){
    if(msh[q]==0) return q; else return msh[q]=fnd(msh[q]);
}
void mrg(int q, int w){
    q=fnd(q);w=fnd(w);
    if(q==w) return;
    pas+=e;
    if(zm[q]<zm[w]) swap(q,w);
    msh[w]=q;
    if(zm[q]==zm[w]) zm[q]++;
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;map <int, int> ma;
    zx=0;
    for(i=1; i<=a; i++){
        cin>>c;
        if(ma[c]!=-1){
            ma[c]=-1;
            zx++;f[zx]=c;
        }
    }
    a=zx;
    for(i=1; i<=a; i++){
        //cin>>f[i];
        fx[f[i]]=i;
    }
    for(i=10000000; i>=0; i--){
        if(fx[i]==0) fx[i]=fx[i+1];
    }
    for(i=1; i<=a; i++){
        for(j=f[i]; j<=10000000; j+=f[i]){
            if(j==f[i]) c=fx[j+1]; else c=fx[j];
            if(c==0||f[c]-j>=f[i]) continue;
            zx=(f[c]-j)%f[i];
            P.push_back({zx,{i,c}});
        }
    }
    sort(P.begin(),P.end());
    for(ii=0; ii<P.size(); ii++){
        e=P[ii].first;c=P[ii].second.first;d=P[ii].second.second;
        mrg(c,d);
    }
    cout<<pas;
    return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:44:17: 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]
   44 |     for(ii=0; ii<P.size(); ii++){
      |               ~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 39636 KB Output is correct
2 Correct 109 ms 42604 KB Output is correct
3 Correct 53 ms 39788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 39624 KB Output is correct
2 Correct 308 ms 40396 KB Output is correct
3 Correct 50 ms 39740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 39652 KB Output is correct
2 Correct 46 ms 39484 KB Output is correct
3 Correct 45 ms 39676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 57072 KB Output is correct
2 Correct 1087 ms 93240 KB Output is correct
3 Correct 484 ms 68048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 43388 KB Output is correct
2 Correct 614 ms 89376 KB Output is correct
3 Correct 435 ms 56472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 711 ms 93740 KB Output is correct
2 Correct 1418 ms 142720 KB Output is correct
3 Correct 442 ms 68936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 261 ms 47552 KB Output is correct
2 Correct 1405 ms 141780 KB Output is correct
3 Correct 450 ms 68340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 330 ms 69292 KB Output is correct
2 Correct 4780 ms 438492 KB Output is correct
3 Correct 347 ms 69192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 313 ms 69208 KB Output is correct
2 Execution timed out 5117 ms 437720 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 43572 KB Output is correct
2 Execution timed out 5117 ms 437252 KB Time limit exceeded
3 Halted 0 ms 0 KB -