제출 #669191

#제출 시각아이디문제언어결과실행 시간메모리
669191Quan2003Sirni (COCI17_sirni)C++17
0 / 140
395 ms481380 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int sz=1e7+1; const int mod=1e9+7; int n,q,timer; long long d; long long a[sz]; long long p[sz]; long long dp[sz]; int freq[sz]; int cnt[sz]; int cntr[sz]; vector<pair<int,int>>edge[sz]; int parent[sz]; int compsize[sz]; void init(int n){ for (int i = 1; i <= n; i++){ parent[i] = i; compsize[i] = 1; } } int find(int a){ if (a == parent[a]) return a; return parent[a] = find(parent[a]); } void unite(int a, int b){ int roota = find(a), rootb = find(b); if (roota == rootb) return ; if (compsize[roota] > compsize[rootb]) swap(roota, rootb); parent[roota] = rootb; compsize[rootb] += compsize[roota]; } int main(){ cin>>n; int bound = 0; for(int i = 1; i <= n; i++){ int x; cin>>x; a[x]++; p[x] = x; bound = max(bound,x); } init(bound); for(int i = bound ; i > 0; i--){ if(!a[i]) p[i] = p[i+1]; } for(int i = 1; i <= bound; i++){ if(!a[i]) continue; for(int j = i; j <= bound; j+=i){ int l = (i == j) ? i + 1: j; int rr = min(i + j - 1,bound); if(p[l] <= rr) edge[p[l]%i].push_back({p[l],i}); } } int ans = 0; for(int i = 1; i <= bound; i++){ for(int j = 0; j < edge[i].size(); j++){ int u = edge[i][j].first; int v = edge[i][j].second; if(find(u) == find(v)) continue; unite(u,v); ans+=i; } } cout<<ans<<endl; }

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

sirni.cpp: In function 'int main()':
sirni.cpp:56:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |            for(int j = 0; j < edge[i].size(); j++){
      |                           ~~^~~~~~~~~~~~~~~~
#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...