# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
490202 |
2021-11-26T09:39:36 Z |
Killer2501 |
Sirni (COCI17_sirni) |
C++14 |
|
3606 ms |
746848 KB |
#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
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 time |
Memory |
Grader output |
1 |
Correct |
170 ms |
274368 KB |
Output is correct |
2 |
Correct |
246 ms |
303272 KB |
Output is correct |
3 |
Correct |
141 ms |
274520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
235292 KB |
Output is correct |
2 |
Correct |
1461 ms |
668792 KB |
Output is correct |
3 |
Correct |
141 ms |
275100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
274444 KB |
Output is correct |
2 |
Correct |
146 ms |
274284 KB |
Output is correct |
3 |
Correct |
156 ms |
274520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
168 ms |
249772 KB |
Output is correct |
2 |
Correct |
294 ms |
277928 KB |
Output is correct |
3 |
Correct |
190 ms |
260944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
241004 KB |
Output is correct |
2 |
Correct |
236 ms |
263048 KB |
Output is correct |
3 |
Correct |
160 ms |
248272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
261516 KB |
Output is correct |
2 |
Correct |
347 ms |
295928 KB |
Output is correct |
3 |
Correct |
191 ms |
259196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
239604 KB |
Output is correct |
2 |
Correct |
332 ms |
296420 KB |
Output is correct |
3 |
Correct |
193 ms |
260796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
288316 KB |
Output is correct |
2 |
Correct |
1713 ms |
633612 KB |
Output is correct |
3 |
Correct |
299 ms |
292860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
292784 KB |
Output is correct |
2 |
Correct |
3606 ms |
746848 KB |
Output is correct |
3 |
Correct |
486 ms |
348888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
276740 KB |
Output is correct |
2 |
Correct |
3482 ms |
635352 KB |
Output is correct |
3 |
Correct |
213 ms |
263092 KB |
Output is correct |