Submission #86504

# Submission time Handle Problem Language Result Execution time Memory
86504 2018-11-26T11:42:13 Z Pluton Sirni (COCI17_sirni) C++14
42 / 140
1418 ms 787456 KB
#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....

Compilation message

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 time Memory Grader output
1 Correct 133 ms 12760 KB Output is correct
2 Correct 164 ms 12884 KB Output is correct
3 Correct 151 ms 12940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 13132 KB Output is correct
2 Correct 200 ms 13132 KB Output is correct
3 Correct 150 ms 13132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 13132 KB Output is correct
2 Correct 120 ms 13148 KB Output is correct
3 Correct 148 ms 13148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1418 ms 787456 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1336 ms 787456 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1358 ms 787456 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1341 ms 787456 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1367 ms 787456 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1349 ms 787456 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1313 ms 787456 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -