# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1021218 |
2024-07-12T15:45:58 Z |
pan |
Sirni (COCI17_sirni) |
C++17 |
|
1774 ms |
786432 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;
vector<pii> edges;
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);
assert(n <= 100000);
for (ll i=0; i<n; ++i) {input(p); dis.pb(p);}
discretize(dis);
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.pb(mp(mp(i, nxt), min(dis[i]%dis[nxt], dis[nxt]%dis[i])));
if (nxt > 0 ) edges.pb(mp(mp(i, nxt-1), min(dis[i]%dis[nxt-1], dis[nxt-1]%dis[i])));
last = nxt;
}
}
sort(all(edges), 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:56: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]
56 | for (ll i=0; i<dis.size(); ++i)
| ~^~~~~~~~~~~
sirni.cpp:69: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]
69 | 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(p); dis.pb(p);}
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
860 KB |
Output is correct |
2 |
Correct |
73 ms |
12780 KB |
Output is correct |
3 |
Correct |
5 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
856 KB |
Output is correct |
2 |
Correct |
346 ms |
3528 KB |
Output is correct |
3 |
Correct |
4 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
386 ms |
100988 KB |
Output is correct |
2 |
Correct |
1393 ms |
199644 KB |
Output is correct |
3 |
Correct |
501 ms |
100936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
12996 KB |
Output is correct |
2 |
Correct |
704 ms |
199296 KB |
Output is correct |
3 |
Correct |
382 ms |
100940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
839 ms |
199656 KB |
Output is correct |
2 |
Correct |
1774 ms |
396472 KB |
Output is correct |
3 |
Correct |
488 ms |
100940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
25960 KB |
Output is correct |
2 |
Correct |
1717 ms |
396588 KB |
Output is correct |
3 |
Correct |
458 ms |
101024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
510 ms |
101200 KB |
Output is correct |
2 |
Runtime error |
1262 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
479 ms |
101184 KB |
Output is correct |
2 |
Runtime error |
1359 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
13112 KB |
Output is correct |
2 |
Runtime error |
1136 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |