Submission #1060463

#TimeUsernameProblemLanguageResultExecution timeMemory
1060463khanhtbSirni (COCI17_sirni)C++14
42 / 140
749 ms707772 KiB
#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 (stderr)

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 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...