Submission #582431

# Submission time Handle Problem Language Result Execution time Memory
582431 2022-06-23T18:32:38 Z mosiashvililuka Sirni (COCI17_sirni) C++14
140 / 140
4061 ms 585072 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;
vector <pair <int, int> > P[10000009];
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}});
            P[zx].push_back({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);
    }*/
    for(i=0; i<=10000000; i++){
        for(ii=0; ii<P[i].size(); ii++){
            e=i;c=P[i][ii].first;d=P[i][ii].second;
            mrg(c,d);
        }
    }
    cout<<pas;
    return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:51:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(ii=0; ii<P[i].size(); ii++){
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 188 ms 274480 KB Output is correct
2 Correct 210 ms 277084 KB Output is correct
3 Correct 175 ms 274636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 271 ms 274544 KB Output is correct
2 Correct 527 ms 275080 KB Output is correct
3 Correct 184 ms 274528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 274492 KB Output is correct
2 Correct 194 ms 274256 KB Output is correct
3 Correct 191 ms 274524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 457 ms 289176 KB Output is correct
2 Correct 951 ms 314840 KB Output is correct
3 Correct 490 ms 293332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 245 ms 276684 KB Output is correct
2 Correct 696 ms 296900 KB Output is correct
3 Correct 577 ms 288492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 781 ms 300528 KB Output is correct
2 Correct 1016 ms 328272 KB Output is correct
3 Correct 483 ms 292220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 358 ms 279516 KB Output is correct
2 Correct 1170 ms 324840 KB Output is correct
3 Correct 455 ms 290652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 292492 KB Output is correct
2 Correct 1822 ms 492788 KB Output is correct
3 Correct 387 ms 294864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 292136 KB Output is correct
2 Correct 3481 ms 585072 KB Output is correct
3 Correct 466 ms 298680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 277704 KB Output is correct
2 Correct 4061 ms 581696 KB Output is correct
3 Correct 483 ms 293344 KB Output is correct