# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
126404 | 2019-07-07T15:40:06 Z | letrongdat | Sirni (COCI17_sirni) | C++17 | 520 ms | 298744 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+ 1; const int maxN = 1e5 +10; int N; int Near[maxM]; int lab[maxN]; 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); 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()) { for(int j = P[i]; j <= P.back(); j += P[i]) { int weight = P[Near[j]] - j; Edge[weight].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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 338 ms | 274808 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 275 ms | 275076 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 336 ms | 274996 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 373 ms | 285932 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 295 ms | 277072 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 489 ms | 298744 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 310 ms | 278672 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 520 ms | 289468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 519 ms | 293540 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 347 ms | 277396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |