Submission #241006

#TimeUsernameProblemLanguageResultExecution timeMemory
241006SamAndSirni (COCI17_sirni)C++17
140 / 140
2922 ms785400 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define fi first #define se second typedef long long ll; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 100005, M = 10000007; int n; int a[N]; int u[M], uu[M]; vector<pair<int, int> > v[M]; int p[N]; int fi(int x) { if (x == p[x]) return x; return p[x] = fi(p[x]); } void kpc(int x, int y) { x = fi(x); y = fi(y); p[x] = y; } void solv() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); u[a[i]] = i; } for (int i = M - 2; i >= 0; --i) { if (u[i]) { uu[i] = u[i]; } else { uu[i] = uu[i + 1]; } } for (int i = 1; i < M; ++i) { if (!u[i]) continue; v[a[uu[i + 1]] % i].push_back(m_p(u[i], uu[i + 1])); for (int j = i + i; j < M; j += i) { if (uu[j]) { v[a[uu[j]] % i].push_back(m_p(u[i], uu[j])); } } } for (int i = 1; i <= n; ++i) p[i] = i; int ans = 0; for (int i = 0; i < M; ++i) { for (int j = 0; j < v[i].size(); ++j) { int x = v[i][j].fi; int y = v[i][j].se; if (fi(x) != fi(y)) { kpc(x, y); ans += i; } } } printf("%d\n", ans); } int main() { #ifdef SOMETHING freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif // SOMETHING //ios_base::sync_with_stdio(false), cin.tie(0); solv(); return 0; } //while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}

Compilation message (stderr)

sirni.cpp: In function 'void solv()':
sirni.cpp:71:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < v[i].size(); ++j)
                         ~~^~~~~~~~~~~~~
sirni.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
sirni.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
#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...