Submission #490202

#TimeUsernameProblemLanguageResultExecution timeMemory
490202Killer2501Sirni (COCI17_sirni)C++14
140 / 140
3606 ms746848 KiB
#include<bits/stdc++.h> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define task "test" #define pii pair<pll, pll> using namespace std; using ll = int; const int N = 1e5+5; const ll mod = 1e8+7; const ll base = 113; const ll inf = 1e9; ll m, n, t, k, a[N], tong, d[N], b[N], h[N], ans, near[N*100]; vector<pll> adj[N*100]; vector<ll> kq; vector<pll> val; ll pw(ll k, ll n, ll md) { ll total = 1; for(; n; n >>= 1) { if(n&1)total = total * k % md; k = k * k % md; } return total; } struct DSU { ll n; vector<ll> lab; DSU(ll _n) { n = _n; lab.resize(n+1, -1); } ll findp(ll u) { return lab[u] < 0 ? u : lab[u] = findp(lab[u]); } bool hop(ll u, ll v) { u = findp(u); v = findp(v); if(u == v)return false; if(lab[u] > lab[v])swap(u, v); lab[u] += lab[v]; lab[v] = u; return true; } }; struct BIT { ll n; vector<ll> fe; BIT(ll _n) { n = _n; fe.resize(n+1, 0); } void reset() { fill(fe.begin(), fe.end(), 0); } void add(ll id, ll x) { for(; id <= n; id += id & -id)fe[id] += x; } ll get(ll id) { ll total = 0; for(; id ; id -= id & -id)total += fe[id]; return total; } }; string s; void sol() { cin >> n; for(int i = 1; i <= n; i ++) { cin >> a[i]; kq.pb(a[i]); } sort(kq.begin(), kq.end()); kq.erase(unique(kq.begin(), kq.end()), kq.end()); m = kq.back(); for(int i = 0; i < kq.size(); i ++) { for(int j = t+1; j <= kq[i]; j ++)near[j] = i; t = kq[i]; } for(int i = 0; i < kq.size()-1; i ++) { for(int j = kq[i]; j <= m; j += kq[i]) { if(near[j] != i)k = near[j]; else if(near[j+1] != i)k = near[j+1]; else continue; //cout << kq[i] <<" "<< kq[near[j]] << '\n'; adj[kq[k] % kq[i]].pb({k, i}); } } DSU dsu(kq.size()); long long ans = 0; for(int i = 0; i <= m; i ++) { for(pll x: adj[i]) { if(dsu.hop(x.fi, x.se)) { //cout << kq[x.fi] <<" "<< kq[x.se] << '\n'; ans += i; } } } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); }

Compilation message (stderr)

sirni.cpp: In function 'void sol()':
sirni.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(int i = 0; i < kq.size(); i ++)
      |                    ~~^~~~~~~~~~~
sirni.cpp:93:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for(int i = 0; i < kq.size()-1; i ++)
      |                    ~~^~~~~~~~~~~~~
sirni.cpp: In function 'int main()':
sirni.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         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...