# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1021299 |
2024-07-12T16:45:13 Z |
pan |
Sirni (COCI17_sirni) |
C++17 |
|
977 ms |
748016 KB |
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%d", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i)
#define RFOR(i, x, n) for (ll i =x; i>=n; --i)
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef int ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;
ll p;
vector<ll> dis;
bool compare(pii &a , pii &b)
{
return a.s < b.s;
}
ll par[100005], siz[100005];
vector<pi> bucket[10000005];
ll nxt[10000005];
inline ll find(ll x)
{
if (x==par[x]) return x;
return par[x] = find(par[x]);
}
inline void unite(ll x, ll y)
{
x = find(x), y = find(y);
if (x==y) return;
if (siz[x] < siz[y]) swap(x,y);
par[y] = x;
siz[x] += siz[y];
}
int main()
{
ll n;
long long ans = 0;
input(n);
dis.resize(n);
for (ll i=0; i<n; ++i) {input(dis[i]);}
discretize(dis);
for (ll i=0; i<= dis.back(); ++i)nxt[i] = -1;
for (ll i=0; i<dis.size(); ++i) nxt[dis[i]] = i;
for (ll i=dis.back(); i>=0; --i) if (nxt[i]==-1) nxt[i] = nxt[i+1];
for (ll i=0; i<dis.size(); ++i)
{
if (i + 1 < dis.size()) bucket[dis[i+1]%dis[i]].pb(mp(i, i+1));
for (ll j=dis[i]; j<=dis.back(); j+=dis[i])
{
bucket[dis[nxt[j]]%dis[i]].pb(mp(i, nxt[j]));
}
}
for (ll i=0; i<dis.size(); ++i) par[i] = i, siz[i] = 1;
ll cnt = 0;
for (ll i=0; i<ll(1e7)&& cnt < ll(dis.size())-1; ++i)
{
for (pi u: bucket[i])
{
if (find(u.f)==find(u.s)) continue;
ans += ll(i);
unite(u.f, u.s);
cnt++;
}
}
print(ans, '\n');
return 0;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:70:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (ll i=0; i<dis.size(); ++i) nxt[dis[i]] = i;
| ~^~~~~~~~~~~
sirni.cpp:72:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (ll i=0; i<dis.size(); ++i)
| ~^~~~~~~~~~~
sirni.cpp:74:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if (i + 1 < dis.size()) bucket[dis[i+1]%dis[i]].pb(mp(i, i+1));
| ~~~~~~^~~~~~~~~~~~
sirni.cpp:80:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for (ll i=0; i<dis.size(); ++i) par[i] = i, siz[i] = 1;
| ~^~~~~~~~~~~
sirni.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input(x) scanf("%d", &x);
| ~~~~~^~~~~~~~~~
sirni.cpp:65:2: note: in expansion of macro 'input'
65 | input(n);
| ^~~~~
sirni.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input(x) scanf("%d", &x);
| ~~~~~^~~~~~~~~~
sirni.cpp:67:26: note: in expansion of macro 'input'
67 | for (ll i=0; i<n; ++i) {input(dis[i]);}
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
274492 KB |
Output is correct |
2 |
Correct |
156 ms |
303904 KB |
Output is correct |
3 |
Correct |
113 ms |
274772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
237396 KB |
Output is correct |
2 |
Correct |
743 ms |
669040 KB |
Output is correct |
3 |
Correct |
128 ms |
275028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
274416 KB |
Output is correct |
2 |
Correct |
114 ms |
274260 KB |
Output is correct |
3 |
Correct |
129 ms |
274516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
252552 KB |
Output is correct |
2 |
Correct |
179 ms |
281452 KB |
Output is correct |
3 |
Correct |
143 ms |
265912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
243436 KB |
Output is correct |
2 |
Correct |
159 ms |
264912 KB |
Output is correct |
3 |
Correct |
134 ms |
250968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
264508 KB |
Output is correct |
2 |
Correct |
190 ms |
298700 KB |
Output is correct |
3 |
Correct |
144 ms |
262316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
242096 KB |
Output is correct |
2 |
Correct |
196 ms |
299480 KB |
Output is correct |
3 |
Correct |
134 ms |
263868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
166 ms |
289164 KB |
Output is correct |
2 |
Correct |
716 ms |
634744 KB |
Output is correct |
3 |
Correct |
164 ms |
292572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
171 ms |
293656 KB |
Output is correct |
2 |
Correct |
977 ms |
748016 KB |
Output is correct |
3 |
Correct |
264 ms |
348560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
276960 KB |
Output is correct |
2 |
Correct |
852 ms |
635740 KB |
Output is correct |
3 |
Correct |
145 ms |
266684 KB |
Output is correct |