제출 #406846

#제출 시각아이디문제언어결과실행 시간메모리
406846FalconSirni (COCI17_sirni)C++17
0 / 140
356 ms248420 KiB
#include <bits/stdc++.h> #ifdef DEBUG #include "debug.hpp" #endif using namespace std; #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); ++it) #define rep(i, N) for(int i = 0; i < (N); ++i) #define rrep(i, N) for(int i = (N) - 1; i >= 0; --i) #define rep1(i, N) for(int i = 1; i <= (N); ++i) #define rep2(i, s, e) for(int i = (s); i <= (e); ++i) #ifdef DEBUG #define debug(x...) { \ ++dbg::depth; \ string dbg_vals = dbg::to_string(x); \ --dbg::depth; \ dbg::fprint(__func__, __LINE__, #x, dbg_vals); \ } #define light_debug(x) { \ dbg::light = true; \ dbg::dout << __func__ << ":" << __LINE__; \ dbg::dout << " " << #x << " = " << x << endl; \ dbg::light = false; \ } #else #define debug(x...) 42 #define light_debug(x) 42 #endif using ll = long long; template<typename T> inline T& ckmin(T& a, T b) { return a = a > b ? b : a; } template<typename T> inline T& ckmax(T& a, T b) { return a = a < b ? b : a; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> p(n); rep(i, n) cin >> p[i]; sort(all(p)); p.erase(unique(all(p)), p.end()); int m{p.back()}; vector<vector<pair<int, int>>> edges(m + 1); rep(i, n) { for(int x{p[i]}; x <= m; x += p[i]) { int j = lower_bound(all(p), x) - p.begin(); if(p[j] < x + p[i]) edges[p[j] - x].push_back({i, j}); } } debug(edges); vector<int> pre(n); iota(all(pre), 0); auto root = [&](int i) { int j; for(j = i; pre[j] != j; j = pre[j]); for(int t{i}; i != j; i = pre[i], pre[t] = j, t = i); return j; }; long long ans{}; auto merge = [&](int i, int j, int c) { debug(i, j); i = root(i), j = root(j); if(i == j) return false; pre[i] = j; ans += c; debug(ans); return true; }; int c{}; rep(i, m + 1) { if(c == n - 1) break; for(auto [u, v] : edges[i]) { if(c == n - 1) break; c += merge(u, v, i); } } cout << ans << '\n'; #ifdef DEBUG dbg::dout << "\nExecution time: " << clock() * 1000 / CLOCKS_PER_SEC << "ms" << endl; #endif return 0; }

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

sirni.cpp: In function 'int main()':
sirni.cpp:33:29: warning: statement has no effect [-Wunused-value]
   33 | #define debug(x...)         42
      |                             ^~
sirni.cpp:64:5: note: in expansion of macro 'debug'
   64 |     debug(edges);
      |     ^~~~~
sirni.cpp: In lambda function:
sirni.cpp:33:29: warning: statement has no effect [-Wunused-value]
   33 | #define debug(x...)         42
      |                             ^~
sirni.cpp:78:9: note: in expansion of macro 'debug'
   78 |         debug(i, j);
      |         ^~~~~
sirni.cpp:33:29: warning: statement has no effect [-Wunused-value]
   33 | #define debug(x...)         42
      |                             ^~
sirni.cpp:83:9: note: in expansion of macro 'debug'
   83 |         debug(ans);
      |         ^~~~~
#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...