제출 #1057683

#제출 시각아이디문제언어결과실행 시간메모리
1057683vjudge1Sirni (COCI17_sirni)C++17
140 / 140
669 ms662256 KiB
#include<bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, b, a) for(int i = (b), _a = (a); i >= _a; --i) #define REP(i, a, b) for(int i = (a), _b = (b); i < _b; ++i) #define REPD(i, b, a) for(int i = (b), _a = (a); i > _a; --i) #define MASK(i) (1LL << (i)) #define BIT(mask, i) (((mask) >> (i)) & 1) #define __builtin_popcount __builtin_popcountll #define all(val) val.begin(), val.end() #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pll pair<ll, ll> #define sz(v) (int)v.size() #define fi first #define se second mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll Rand(ll l, ll r) {return l + rng() % (r - l + 1);} template<class X, class Y> bool minimize(X &x, const Y &y) { if (x > y) { x = y; return true; } else return false; } template<class X, class Y> bool maximize(X &x, const Y &y) { if (x < y) { x = y; return true; } else return false; } template<class T> T Abs(const T &x) { return (x < 0 ? -x : x); } const int mod = 1e9 + 7; const int inf = 1e9; const int N = 1e5 + 5; const int MAX = 1e7 + 5; int n, a[N], nxt[MAX]; bool exist[MAX]; int par[MAX], sz[MAX]; vector<pii> g[MAX]; int mx; int find(int u) { if(u == par[u]) return u; return par[u] = find(par[u]); } bool join(int u, int v) { u = find(u); v = find(v); if(u == v) return false; if(sz[u] < sz[v]) swap(u, v); sz[u] += sz[v]; par[v] = u; return true; } void process() { cin >> n; FOR(i, 1, n) { cin >> a[i]; nxt[a[i]] = a[i]; mx = max(mx, a[i]); exist[a[i]] = 1; } FORD(i, mx, 0) { if(!exist[i]) nxt[i] = nxt[i + 1]; } sort(a + 1, a + n + 1); FOR(i, 1, n) { if(!exist[a[i]]) continue; for(int j = a[i]; j <= mx; j += a[i]) { int res = (a[i] == j) ? a[i] + 1 : j; if(a[i] + j > nxt[res]) g[nxt[res] % a[i]].push_back({nxt[res], a[i]}); } exist[a[i]] = 0; } int ans = 0; FOR(i, 1, mx) par[i] = i, sz[i] = 1; FOR(i, 0, mx) { for(auto [u, v] : g[i]) { if(join(u, v)) ans += i; } } cout << ans << '\n'; } signed main() { if(fopen("test.inp","r")) { freopen("test.inp","r",stdin); freopen("test.out","w",stdout); } ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // clock_t start = clock(); int ntests = 1; // cin >> ntests; while(ntests--) process(); // cerr << "Time elapsed: " << clock() - start << " ms!\n"; return 0; }

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

sirni.cpp: In function 'int main()':
sirni.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...