Submission #1124803

#TimeUsernameProblemLanguageResultExecution timeMemory
1124803KhanhDangSirni (COCI17_sirni)C++20
0 / 140
970 ms107000 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define fi first #define se second #define all(v) (v).begin(),(v).end() #define Unique(v) sort(all(v)); (v).erase(unique(all(v)), (v).end()); const ll N = 1e5+5; ll n, ans; ll par[N]; map<ll, ll> f; vector<ll> pos; struct Edge { ll u, v, w; }; vector<Edge> e; ll findSet(ll u) { return (u == par[u] ? u : par[u] = findSet(par[u])); } void unionSet(ll u, ll v) { u = findSet(u); v = findSet(v); par[u] = v; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "task" if (fopen(task".INP", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } if (fopen("task.INP", "r")) { freopen("task.INP", "r", stdin); freopen("task.OUT", "w", stdout); } cin>>n; for (int i = 1; i <= n; i++) par[i] = i; for (int i = 1; i <= n; i++) { ll x; cin>>x; pos.push_back(x); if (f[x] == 0) f[x] = i; else unionSet(f[x], i); } Unique(pos); for (auto x : pos) { for (int i = 1; ; i++) { auto it = lower_bound(all(pos), x * i); if (it == pos.end()) break; else e.push_back({f[x], f[*it], (*it) % x}); } } sort(all(e), [&] (Edge a, Edge b) { return a.w < b.w; }); for (auto x : e) if (findSet(x.u) != findSet(x.v)) { unionSet(x.u, x.v); ans += x.w; } cout<<ans; }

Compilation message (stderr)

sirni.cpp: In function 'int main()':
sirni.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen("task.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen("task.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...