Submission #1060463

# Submission time Handle Problem Language Result Execution time Memory
1060463 2024-08-15T15:25:44 Z khanhtb Sirni (COCI17_sirni) C++14
42 / 140
749 ms 707772 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7; 
const ll inf = 2e18;
const ll B = 320;
const ll N = 1e5+8;
ll n;
vector<ll> a;
ll par[N];
ll fs(ll v){
    return ((par[v]<0)?v:par[v]=fs(par[v]));
}
bool ss(ll u, ll v){
    return fs(u) == fs(v);
}
void us(ll u, ll v){
    if(ss(u,v)) return;
    ll x = fs(u);
    ll y = fs(v);
    if(par[x] > par[y]) swap(x,y);
    par[y]+=par[x];
    par[x]=y;
}
ll tw = 0;
void solve(){
    cin >> n;
    fill(par,par+n+10,-1);
    for(ll i = 1; i <= n; i++){
        ll x;cin >> x;
        a.pb(x);
    }
    ll ans = 0;
    sort(all(a));
    a.erase(unique(all(a)),a.end());
    ll mx = a.back();
    vector<ll> opt(mx+1,-1);
    for(ll i = 0; i < a.size(); i++) opt[a[i]] = i;
    for(ll i = mx-1; i >= 0; i--){
        if(opt[i] == -1) opt[i] = opt[i+1];
    }
    vector<vector<pair<int,int>>> edge_mod(mx+1);
    for(ll i = 0; i < a.size()-1; i++){
        edge_mod[a[i+1] % a[i]].pb({i+1,i});
        for(ll j = 2*a[i]; j <= mx; j += a[i]){
            ll p = opt[j];
            edge_mod[a[p] % a[i]].pb({i,p});
        }
    }
    for(ll md = 0; md <= mx; md++){
        for(pair<ll,ll> e:edge_mod[md]){
            if(ss(e.fi,e.se)) continue;
            tw += md;
            us(e.fi,e.se);
        }
    }
    cout << tw;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if (fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }   
    ll T = 1;
    // cin >> T;
    for (ll i = 1; i <= T; i++) {
        solve();
        cout << '\n';
    }
}

Compilation message

sirni.cpp: In function 'void solve()':
sirni.cpp:49:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(ll i = 0; i < a.size(); i++) opt[a[i]] = i;
      |                   ~~^~~~~~~~~~
sirni.cpp:54:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(ll i = 0; i < a.size()-1; i++){
      |                   ~~^~~~~~~~~~~~
sirni.cpp:44:8: warning: unused variable 'ans' [-Wunused-variable]
   44 |     ll ans = 0;
      |        ^~~
sirni.cpp: In function 'int main()':
sirni.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 133 ms 313496 KB Output is correct
2 Correct 209 ms 341604 KB Output is correct
3 Correct 137 ms 312436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 749 ms 707772 KB Output is correct
3 Correct 140 ms 314192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 313428 KB Output is correct
2 Correct 142 ms 312820 KB Output is correct
3 Correct 147 ms 313680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 2136 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 33828 KB Output is correct
2 Runtime error 2 ms 2140 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 11196 KB Output is correct
2 Runtime error 1 ms 2140 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 139 ms 316120 KB Output is correct
2 Runtime error 1 ms 2140 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -