답안 #482452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482452 2021-10-24T15:23:13 Z MilosMilutinovic Sirni (COCI17_sirni) C++14
84 / 140
1136 ms 786436 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=101000;
int n,_[N],a[N],id[10000005],f[N];
int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}
struct edge{
	int u,v; ll w;
	bool operator<(const edge oth) const{return w<oth.w;}
};
vector<edge> ed;
bool x[10000005];
int main() {
	scanf("%d",&n);
	rep(i,0,n) f[i]=i;
	rep(i,0,n) scanf("%d",_+i),x[_[i]]=true;
	sort(_,_+n);
	int nxt=0;
	rep(i,0,n) if (i==0||_[i]!=_[i-1]) a[nxt++]=_[i]; n=nxt;
	int pos=n-1;
	id[10000002]=0;
	per(i,1,10000002) {
		if (x[i]) id[i]=pos,pos--;
		else id[i]=id[i+1];
	}
	rep(i,0,n) {
		for (int j=a[i];j<=a[n-1];j+=a[i]) {
			int x=id[j+(j==a[i]?1:0)];
			ed.pb({i,x,a[x]%a[i]});
		}
	}
	sort(all(ed));
	ll ans=0;
	for (auto e:ed) {
		int x=find(e.u);
		int y=find(e.v);
		if (x!=y) {
			ans+=e.w;
			f[x]=y;
		}
	}
	printf("%lld",ans);
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:3:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    3 | #define rep(i,a,n) for (int i=a;i<n;i++)
      |                    ^~~
sirni.cpp:39:2: note: in expansion of macro 'rep'
   39 |  rep(i,0,n) if (i==0||_[i]!=_[i-1]) a[nxt++]=_[i]; n=nxt;
      |  ^~~
sirni.cpp:39:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   39 |  rep(i,0,n) if (i==0||_[i]!=_[i-1]) a[nxt++]=_[i]; n=nxt;
      |                                                    ^
sirni.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
sirni.cpp:36:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  rep(i,0,n) scanf("%d",_+i),x[_[i]]=true;
      |             ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 42736 KB Output is correct
2 Correct 224 ms 106968 KB Output is correct
3 Correct 42 ms 43304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 39672 KB Output is correct
2 Runtime error 952 ms 786436 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 42948 KB Output is correct
2 Correct 41 ms 40608 KB Output is correct
3 Correct 43 ms 43136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 74960 KB Output is correct
2 Correct 378 ms 107360 KB Output is correct
3 Correct 223 ms 107364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 44836 KB Output is correct
2 Correct 264 ms 107040 KB Output is correct
3 Correct 143 ms 74008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 107780 KB Output is correct
2 Correct 497 ms 173076 KB Output is correct
3 Correct 185 ms 74692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 48448 KB Output is correct
2 Correct 523 ms 173144 KB Output is correct
3 Correct 189 ms 74504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 83820 KB Output is correct
2 Runtime error 967 ms 786436 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 83792 KB Output is correct
2 Runtime error 965 ms 786436 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 53596 KB Output is correct
2 Runtime error 1136 ms 786436 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -