# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
126497 | 2019-07-08T00:11:52 Z | letrongdat | Sirni (COCI17_sirni) | C++17 | 3288 ms | 513284 KB |
#include <bits/stdc++.h> using namespace std; #define forn(i, a, b) for(int i=a; i<=b; ++i) #define ford(i, a ,b) for(int i=a; i>=b; --i) #define repn(i, a, b) for(int i=a; i <b; ++i) typedef pair<int, int> ii; const int maxM = 1e7+ 10; const int maxN = 1e5 +10; int N; int Near[maxM]; int lab[maxN]; bool flag[maxM]; vector<int> P; vector<ii> Edge[maxM]; int root(int u) { if (lab[u] < 0) return u; return lab[u] = root(lab[u]); } bool join(int u, int v) { int l1 = root(u), l2 = root(v); if (l1 == l2) return false; if (lab[l1] > lab[l2]) swap(l1, l2); lab[l1] += lab[l2]; lab[l2] = l1; return true; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(lab, -1, sizeof lab); cin >> N; P.resize(N); repn(i, 0, N) cin >> P[i]; sort(P.begin(), P.end()); P.resize(unique(P.begin(), P.end()) - P.begin()); memset(Near, 0x3f, sizeof Near); repn(i, 0, P.size()) Near[P[i]] = i; ford(i, P.back(), 0) Near[i] = min(Near[i], Near[i+1]); repn(i, 0, P.size() -1) { int weight = P[Near[P[i]+1]] - P[i]; Edge[weight].push_back({i, Near[P[i]+1]}); if (!flag[P[i]]) for(int j = 2*P[i]; j <= P.back(); j += P[i]) { flag[j] = true; Edge[P[Near[j]] - j].push_back({i, Near[j]}); } } long long result = 0; repn(i, 0, maxM) { for(auto &e: Edge[i]) result += join(e.first, e.second) * i; } cout << result; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 315 ms | 283000 KB | Output is correct |
2 | Correct | 965 ms | 317304 KB | Output is correct |
3 | Correct | 317 ms | 285024 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 275 ms | 274808 KB | Output is correct |
2 | Correct | 3288 ms | 513284 KB | Output is correct |
3 | Correct | 330 ms | 285532 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 317 ms | 283256 KB | Output is correct |
2 | Correct | 314 ms | 280028 KB | Output is correct |
3 | Correct | 346 ms | 284764 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 357 ms | 284072 KB | Output is correct |
2 | Correct | 390 ms | 292512 KB | Output is correct |
3 | Correct | 408 ms | 295500 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 297 ms | 277752 KB | Output is correct |
2 | Correct | 398 ms | 290296 KB | Output is correct |
3 | Correct | 360 ms | 283084 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 570 ms | 289104 KB | Output is correct |
2 | Correct | 465 ms | 295960 KB | Output is correct |
3 | Correct | 361 ms | 288952 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 298 ms | 277640 KB | Output is correct |
2 | Correct | 438 ms | 296544 KB | Output is correct |
3 | Correct | 480 ms | 294988 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 551 ms | 298772 KB | Output is correct |
2 | Correct | 1655 ms | 429268 KB | Output is correct |
3 | Correct | 560 ms | 301556 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 538 ms | 302440 KB | Output is correct |
2 | Correct | 2205 ms | 475368 KB | Output is correct |
3 | Correct | 851 ms | 355088 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 353 ms | 286948 KB | Output is correct |
2 | Correct | 2779 ms | 442864 KB | Output is correct |
3 | Correct | 400 ms | 294460 KB | Output is correct |