제출 #984292

#제출 시각아이디문제언어결과실행 시간메모리
984292faricaSirni (COCI17_sirni)C++17
84 / 140
1174 ms786432 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MAX_N = 100005; int parent[MAX_N], siz[MAX_N]; int find_parent(int x) { if(parent[x] == x) return x; return parent[x] = find_parent(parent[x]); } void unite(int a, int b) { int x = find_parent(a), y = find_parent(b); if(x==y) return; if(siz[x] < siz[y]) swap(x,y); siz[x] += siz[y]; parent[y] = x; } void solve() { int n; cin >> n; vector<int>a; for(int i=0; i<n; ++i) { int tmp; cin >> tmp; assert(tmp>=1); a.push_back(tmp); parent[i] = i; siz[i] = 1; } sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); int largest = a.back(); vector<int>T(largest+1, -1); for(int i=0; i<a.size(); ++i) T[a[i]] = i; for(int i=largest-1; i>=0; --i) { if(T[i] != -1) continue; T[i] = T[i+1]; } int ans = 0; vector<vector<pair<int,int>>>pq(largest+1); for(int i=0; i<a.size()-1; ++i) { pq[a[i+1]%a[i]].push_back({i+1, i}); for(int j=2*a[i]; j<=largest; j+=a[i]) { int p = T[j]; pq[a[p]%a[i]].push_back({p, i}); } } for(int i=0; i<=largest; ++i) { for(pair<int,int>cur: pq[i]) { if(find_parent(cur.first) == find_parent(cur.second)) continue; unite(cur.first,cur.second); ans += i; } } cout << ans << endl; } signed main() { int t=1; while(t--) solve(); return 0; }

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

sirni.cpp: In function 'void solve()':
sirni.cpp:39:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i=0; i<a.size(); ++i) T[a[i]] = i;
      |                  ~^~~~~~~~~
sirni.cpp:46:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0; i<a.size()-1; ++i) {
      |                  ~^~~~~~~~~~~
#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...