답안 #555326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555326 2022-04-30T12:55:12 Z stefantaga Sirni (COCI17_sirni) C++14
112 / 140
5000 ms 669268 KB
#include <bits/stdc++.h>

using namespace std;
int fr[10000005],n,x,i,tata[1000005],rang[1000005];
set <pair <int,int>> m;
vector <pair <int,int>> bonjour[10000005];
int costul(int a,int b)
{
    return min (a%b,b%a);
}
int parinte (int x)
{
    if (x!=tata[x])
    {
        return tata[x]=parinte(tata[x]);
    }
    return x;
}
void uneste(int x,int y)
{
    x=parinte(x);
    y=parinte(y);
    if (rang[x]<rang[y])
    {
        tata[x]=y;
    }
    else
    if (rang[y]<rang[x])
    {
        tata[y]=x;
    }
    else
    {
        tata[x]=y;
        rang[y]++;
    }
}
int v[100005],q,maxim;
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    #ifdef HOME
    ifstream cin("date.in");
    ofstream cout("date.out");
    #endif // HOME
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>x;
        if (fr[x]==0)
        {
            fr[x]=1;
            v[++q]=x;
        }
        maxim=max(maxim,x);
    }
    n=q;
    for (i=1;i<=n;i++)
    {
        m.insert({v[i],i});
    }
    for (i=1;i<=n;i++)
    {
        for (int j=1;j*v[i]<=maxim;j++)
        {
            int val =0;
            if (j==1)
            {
                val=j*v[i]+1;
            }
            else
            {
                val=j*v[i];
            }
            auto ceau = m.lower_bound({val,1});
            if (ceau == m.end())
            {
                break;
            }
            pair <int,int> Locas = (*ceau);
            bonjour[costul(Locas.first,v[i])].push_back({i,Locas.second});
        }
    }
    for (i=1;i<=n;i++)
    {
        tata[i]=i;
        rang[i]=1;
    }
    long long sum=0;
    for (i=0;i<=maxim;i++)
    {
        for (int j=0;j<bonjour[i].size();j++)
        {
            int x = bonjour[i][j].first;
            int y =bonjour[i][j].second;
            if (parinte(x)!=parinte(y))
            {
                sum=sum+i;
                uneste(x,y);
            }
        }
    }
    cout<<sum;
    return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:93:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |         for (int j=0;j<bonjour[i].size();j++)
      |                      ~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 238916 KB Output is correct
2 Correct 255 ms 269688 KB Output is correct
3 Correct 137 ms 239572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 235356 KB Output is correct
2 Correct 2221 ms 662392 KB Output is correct
3 Correct 129 ms 240040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 239268 KB Output is correct
2 Correct 140 ms 237700 KB Output is correct
3 Correct 127 ms 239460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 370 ms 254096 KB Output is correct
2 Correct 906 ms 281956 KB Output is correct
3 Correct 463 ms 266656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 241868 KB Output is correct
2 Correct 344 ms 262632 KB Output is correct
3 Correct 354 ms 252172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 682 ms 265192 KB Output is correct
2 Correct 1128 ms 300732 KB Output is correct
3 Correct 426 ms 263156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 241296 KB Output is correct
2 Correct 1039 ms 301860 KB Output is correct
3 Correct 431 ms 264148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 466 ms 293580 KB Output is correct
2 Correct 4731 ms 663644 KB Output is correct
3 Correct 504 ms 297080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 519 ms 297096 KB Output is correct
2 Execution timed out 5090 ms 669268 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 272768 KB Output is correct
2 Execution timed out 5108 ms 639908 KB Time limit exceeded
3 Halted 0 ms 0 KB -