제출 #547288

#제출 시각아이디문제언어결과실행 시간메모리
547288AA_SurelySirni (COCI17_sirni)C++17
140 / 140
3265 ms434116 KiB
#include <bits/stdc++.h> #define FOR(i,x,n) for(int i=x; i<n; i++) #define F0R(i,n) FOR(i,0,n) #define ROF(i,x,n) for(int i=n-1; i>=x; i--) #define R0F(i,n) ROF(i,0,n) #define WTF cout << "WTF" << endl #define IOS ios::sync_with_stdio(false); cin.tie(0) #define F first #define S second #define pb push_back #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<LL> VLL; typedef vector<PII> VPII; typedef vector<PLL> VPLL; const int N = 1e5 + 7; const int A = 1e7 + 7; struct Edge { int u, v, w; inline bool operator < (const Edge other) { return w < other.w; } } x; int n, era[A]; int par[N]; vector<Edge> eset; int grand(int x) { if (par[x] < 0) return x; return par[x] = grand(par[x]); } inline bool merge(int a, int b) { a = grand(a); b = grand(b); if (a == b) return 0; if (par[a] > par[b]) swap(a, b); par[a] += par[b]; par[b] = a; return 1; } int main() { IOS; fill(era, era + A, -1); cin >> n; VI ns(n); F0R(i, n) cin >> ns[i]; sort(ALL(ns)); ns.resize(unique(ALL(ns)) - ns.begin()); n = ns.size(); F0R(i, n) era[ ns[i] ] = i; R0F(i, A - 1) if (era[i] == -1) era[i] = era[i + 1]; F0R(i, n) for(int j = ns[i]; j < A; j += ns[i]) if (era[j] != -1) { if (j + ns[i] >= A || era[j + ns[i]] != era[j]) { x.u = i; x.v = era[j]; x.w = ns[ era[j] ] - j; eset.pb(x); } if ((era[j + 1] != -1 && era[j + 1] != era[j]) && (j + ns[i] >= A || era[j + ns[i]] != era[j + 1])) { x.u = i; x.v = era[j + 1]; x.w = ns[ era[j + 1] ] - j; eset.pb(x); } } sort(ALL(eset)); fill(par, par + n, -1); LL ans = 0; F0R(i, eset.size()) if (merge(eset[i].u, eset[i].v)) ans += eset[i].w; cout << ans << endl; }

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

sirni.cpp: In function 'int main()':
sirni.cpp:3:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define FOR(i,x,n)  for(int i=x; i<n; i++)
      |                                   ^
sirni.cpp:4:19: note: in expansion of macro 'FOR'
    4 | #define F0R(i,n)  FOR(i,0,n)
      |                   ^~~
sirni.cpp:95:5: note: in expansion of macro 'F0R'
   95 |     F0R(i, eset.size()) if (merge(eset[i].u, eset[i].v)) ans += eset[i].w;
      |     ^~~
#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...