답안 #1021196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021196 2024-07-12T15:34:41 Z pan Sirni (COCI17_sirni) C++17
84 / 140
2194 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("%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];
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);
	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;
			bucket[min(dis[i]%dis[nxt], dis[nxt]%dis[i])].pb(mp(i, nxt));
			if (nxt > 0 ) bucket[min(dis[i]%dis[nxt-1], dis[nxt-1]%dis[i])].pb(mp(i, nxt-1));
		}
	}
	for (ll i=0; i<dis.size(); ++i) par[i] = i;
	ll cnt = 0;
	for (ll i=0; i<dis.back() && 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:67:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for (ll i=0; i<dis.size(); ++i)
      |               ~^~~~~~~~~~~
sirni.cpp:78:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |  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("%d", &x);
      |                  ~~~~~^~~~~~~~~~
sirni.cpp:64:2: note: in expansion of macro 'input'
   64 |  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:65:26: note: in expansion of macro 'input'
   65 |  for (ll i=0; i<n; ++i) {input(p); dis.pb(p);}
      |                          ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 235344 KB Output is correct
2 Correct 170 ms 292688 KB Output is correct
3 Correct 95 ms 235944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 235352 KB Output is correct
2 Runtime error 994 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 235348 KB Output is correct
2 Correct 99 ms 235344 KB Output is correct
3 Correct 105 ms 235604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 259232 KB Output is correct
2 Correct 498 ms 316432 KB Output is correct
3 Correct 290 ms 278056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 239956 KB Output is correct
2 Correct 241 ms 281432 KB Output is correct
3 Correct 205 ms 257768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 282760 KB Output is correct
2 Correct 606 ms 344860 KB Output is correct
3 Correct 279 ms 273268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 243472 KB Output is correct
2 Correct 566 ms 348344 KB Output is correct
3 Correct 277 ms 278424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 338 ms 269340 KB Output is correct
2 Runtime error 1653 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 276680 KB Output is correct
2 Runtime error 1560 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 241616 KB Output is correct
2 Runtime error 2194 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -