제출 #86504

#제출 시각아이디문제언어결과실행 시간메모리
86504PlutonSirni (COCI17_sirni)C++14
42 / 140
1418 ms787456 KiB
#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define sz size()
#define all(xx) xx.begin(),xx.end()
#define pb push_back
#define in insert
#define er erase
#define S second
#define F first
#define pii pair <int, int>
#define to_be continue
#define mp make_pair
#define stop exit (0)
#define fname ""
#define speed ios_base::sync_with_stdio(0);cin.tie(0)
#define input freopen (fname".in", "r", stdin)
#define output freopen (fname".out", "w", stdout)
//#define int ll
#define N 1020000

using namespace std;

const int inf = 1e9 + 123;
const ll INF = 1e18 + 123;
const double pi = acos (-1.0);
const ld eps = 1e-3;
                                                   
vector <pair <int, pii > > e;
int ans;
int n, p[N], size[N], a[N];     
 
int get (int x)
{
    if (p[x] == x)
        return x;
    p[x] = get (p[x]);
    return p[x];
}
 
void join (int x, int y)
{
    if (get (x) == get (y))
        return;
    if (size[get (x)] > size[get (y)])
        size[get (x)] += size[get (y)], p[get (y)] = get (x);
    else
        size[get (y)] += size[get (x)], p[get (x)] = get (y);
}
 
int main ()
{
    speed;
    cin >> n;
    for (int i = 1; i <= n; i ++)
        cin >> a[i], p[i] = i, size[i] = 1;
    for (int i = 1; i <= n; i ++)
    	for (int j = 1 + i; j <= n; j ++)
        	e.pb (mp (min (a[i] % a[j], a[j] % a[i]), mp (i, j))), e.pb (mp (min (a[i] % a[j], a[j] % a[i]), mp (j, i)));
    sort (all (e));
    for (int i = 1; i <= e.sz; i ++)
    {
        int x = e[i - 1].S.F;
        int y = e[i - 1].S.S;
        int c = e[i - 1].F;
        if (get (x) != get (y))
        {
            join (x, y);
            ans += c;
        }   
    }
    cout << ans;
}                   
//Coded by A....

컴파일 시 표준 에러 (stderr) 메시지

sirni.cpp: In function 'int main()':
sirni.cpp:62:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i <= e.sz; i ++)
                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...