제출 #540421

#제출 시각아이디문제언어결과실행 시간메모리
540421levladiatorSirni (COCI17_sirni)C++14
0 / 140
710 ms395936 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define pf push_front #define ll long long #define ull unsigned long long #define pii pair<int,int> #define pll pair<ll,ll> #define EPSILON 0.000001 using namespace std; const ll NMAX = 1e7+5, INF = 1e18, MOD = 1e9+7, MMAX = 1e2 + 5, inf = INT_MAX; ifstream fin("date.in"); ofstream fout("aleatoare.out"); int N,maxi; int par[NMAX],siz[NMAX]; set<int> S; vector<pair<int,int> > cnt[NMAX]; ll ans; struct edge { int a,b,cost; }; vector<edge> edges,sorted; int parent(int node) { if(par[node]==node)return node; return(par[node]=parent(par[node])); } void dsu(int a,int b,int cost) { a=parent(a); b=parent(b); if(a!=b) { if(siz[a]<siz[b])swap(a,b); siz[a]+=siz[b]; par[b]=a; ans+=cost; } } bool cmp(edge a, edge b) { return a.cost<b.cost; } void kruskal() { int maxcost=0; for(auto x : edges) { cnt[x.cost].pb({x.a,x.b}); maxcost=max(maxcost,x.cost); } for(int i=1;i<=maxcost;i++) { for(auto x : cnt[i]) { sorted.pb({x.first,x.second,i}); } } for(auto x : sorted) { int a=x.a; int b=x.b; int cost=x.cost; dsu(a,b,cost); } } int main() { cin.tie ( 0 )->sync_with_stdio ( 0 ); cin.tie ( NULL ); cout.tie ( NULL ); cin>>N; for(int i=1;i<=N;i++) { int x; cin>>x; S.insert(x); par[x]=x; siz[x]=1; maxi=max(maxi,x); } for(auto x : S) { if(x==maxi) { bool ok=1; } auto it=S.upper_bound(x); int a=x; if(it!=S.end()) { int b=*it; int cost=*it-x; edges.pb({a,b,cost}); } for(int j=2*x;j<=maxi;j+=x) { it=S.lower_bound(j); if(it!=S.end()) { int b=*it; int cost=*it-j; edges.pb({a,b,cost}); } } } kruskal(); cout<<ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

sirni.cpp: In function 'int main()':
sirni.cpp:99:18: warning: unused variable 'ok' [-Wunused-variable]
   99 |             bool ok=1;
      |                  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...