Submission #856125

# Submission time Handle Problem Language Result Execution time Memory
856125 2023-10-02T17:14:30 Z vjudge1 Sirni (COCI17_sirni) C++17
42 / 140
322 ms 786432 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast,O3,unroll-loops")
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define vb vector<bool>
#define vvb vector<vb>
#define endl "\n"
#define sp << " " <<
#define F(i, s, n) for(int i = s; i < n; i++)
#define pb push_back
#define fi first
#define se second
int mod = 998244353;

int inf = LLONG_MAX >> 3;

int mult(int x, int y) {
    return (x%mod)*(y%mod)%mod;
}

const int N = 1e7+1;
int dad[N];

int find(int x) {
    if(dad[x] == x) return x;
    return dad[x] = find(dad[x]);
}

void unite(int x, int y) {
    dad[find(x)] = find(y);
}

void solve() {
    int n;
    cin >> n;
    F(i, 0, n) dad[i] = i;
    int a[n];
    F(i, 0, n) cin >> a[i];
    vector<pair<int, pii>> edges;
    F(i, 0, n) {
        F(j, i+1, n) {
            edges.pb({max(a[i], a[j]) % min(a[i], a[j]), {i, j}});
        }
    }
    sort(edges.begin(), edges.end());
    int ans = 0;
    F(i, 0, edges.size()) {
        if(find(edges[i].se.fi) != find(edges[i].se.se)) {
            unite(edges[i].se.fi, edges[i].se.se);
            ans += edges[i].fi;
        }
    }
    cout << ans << endl;
}

void setIO() {
    ios::sync_with_stdio(0); cin.tie(0);
    #ifdef Local
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
}
signed main() {
    setIO();
    int t = 1;
    //cin >> t;
    while(t--) solve();
}

Compilation message

sirni.cpp: In function 'void solve()':
sirni.cpp:15:37: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 | #define F(i, s, n) for(int i = s; i < n; i++)
......
   53 |     F(i, 0, edges.size()) {
      |       ~~~~~~~~~~~~~~~~~~             
sirni.cpp:53:5: note: in expansion of macro 'F'
   53 |     F(i, 0, edges.size()) {
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 42 ms 13764 KB Output is correct
2 Correct 56 ms 14788 KB Output is correct
3 Correct 47 ms 13508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 13256 KB Output is correct
2 Correct 66 ms 14024 KB Output is correct
3 Correct 49 ms 13768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 13256 KB Output is correct
2 Correct 40 ms 14536 KB Output is correct
3 Correct 51 ms 13508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 322 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 313 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 321 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 310 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 315 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 316 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 318 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -