# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1021224 |
2024-07-12T15:58:53 Z |
pan |
Sirni (COCI17_sirni) |
C++17 |
|
1561 ms |
479056 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("%lld", &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 long long 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;
pii edges[10000005];
bool compare(pii a , pii b)
{
return a.s < b.s;
}
ll par[100005];
ll find(ll x) {return ((x==par[x])?x:par[x] = find(par[x]));}
void unite(ll x, ll y) {if ((x=find(x)) != (y=find(y))) par[x] = y;}
int main()
{
ll n, ans=0;
input(n);
dis.resize(n);
for (ll i=0; i<n; ++i) {input(dis[i]);}
discretize(dis);
ll now = 0;
for (ll i=0; i<dis.size(); ++i)
{
ll last = -1;
for (ll j=0; j<=dis.back(); j+=dis[i])
{
ll nxt = lb(all(dis), j)-dis.begin();
if (nxt == last) continue;
if (nxt < ll(dis.size())) edges[now++] = mp(mp(i, nxt), min(dis[i]%dis[nxt], dis[nxt]%dis[i]));
if (nxt > 0 ) edges[now++] = mp(mp(i, nxt-1), min(dis[i]%dis[nxt-1], dis[nxt-1]%dis[i]));
last = nxt;
}
}
sort(edges, edges+now, compare);
for (ll i=0; i<dis.size(); ++i) par[i] = i;
for (pii u: edges)
{
if (find(u.f.f)==find(u.f.s)) continue;
ans += u.s;
unite(u.f.f, u.f.s);
}
print(ans, '\n');
return 0;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:57:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (ll i=0; i<dis.size(); ++i)
| ~^~~~~~~~~~~
sirni.cpp:70:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (ll i=0; i<dis.size(); ++i) par[i] = i;
| ~^~~~~~~~~~~
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("%lld", &x);
| ~~~~~^~~~~~~~~~~~
sirni.cpp:52:2: note: in expansion of macro 'input'
52 | 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("%lld", &x);
| ~~~~~^~~~~~~~~~~~
sirni.cpp:54:26: note: in expansion of macro 'input'
54 | for (ll i=0; i<n; ++i) {input(dis[i]);}
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
1116 KB |
Output is correct |
2 |
Correct |
102 ms |
9772 KB |
Output is correct |
3 |
Correct |
40 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
1104 KB |
Output is correct |
2 |
Correct |
378 ms |
3996 KB |
Output is correct |
3 |
Correct |
39 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
1104 KB |
Output is correct |
2 |
Correct |
37 ms |
976 KB |
Output is correct |
3 |
Correct |
38 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
365 ms |
52728 KB |
Output is correct |
2 |
Correct |
1205 ms |
185984 KB |
Output is correct |
3 |
Correct |
533 ms |
73556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
8020 KB |
Output is correct |
2 |
Correct |
620 ms |
101540 KB |
Output is correct |
3 |
Correct |
349 ms |
53328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
769 ms |
112976 KB |
Output is correct |
2 |
Correct |
1561 ms |
237312 KB |
Output is correct |
3 |
Correct |
458 ms |
68836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
18772 KB |
Output is correct |
2 |
Correct |
1509 ms |
225412 KB |
Output is correct |
3 |
Correct |
434 ms |
65340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
457 ms |
62168 KB |
Output is correct |
2 |
Runtime error |
839 ms |
479056 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
451 ms |
61516 KB |
Output is correct |
2 |
Runtime error |
900 ms |
478804 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
10392 KB |
Output is correct |
2 |
Runtime error |
748 ms |
478700 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |