Submission #636490

#TimeUsernameProblemLanguageResultExecution timeMemory
636490berrSirni (COCI17_sirni)C++17
0 / 140
648 ms243712 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int ans=0; vector<array<int, 2>> val(1e7+5, {(int)1e9, 0}); vector<int> adj((int)(1e7+5), -1); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; vector<int> a(n), b; for(int i=0; i<n; i++) { cin>>a[i]; } sort(a.begin(), a.end()); b.push_back(a[0]); adj[a[0]]=0; for(int i=1; i<n; i++) { if(a[i]!=a[i-1]) { b.push_back(a[i]); adj[a[i]]=i; } else { val[a[i]]={0, n}; val[1e7+3]={0, i}; } } a=b; n=b.size(); a.push_back(1e7+3); for(int i=0; i<n; i++) { int l=a[i]*2; for(l; l<1e7+5; l+=a[i]) { val[l]={0, i}; if(adj[l]!=-1) { if((val[val[i][1]][0]>val[i][0])); { val[val[i][1]]=min(val[val[i][1]], {val[i][0], adj[l]}); } } } } for(int i=1; i<1e7+5; i++) { val[i]=min(val[i], {val[i-1][0]+1, val[i-1][1]}); if(val[i][1]!=-1&&adj[i]!=-1) { val[a[val[i][1]]]=min(val[a[val[i][1]]], {val[i][0], adj[i]}); } } set<array<int, 3>> st; for(auto i: b) { int x=adj[i], y=val[i][1], z=val[i][0]; if(x<y) swap(x, y); st.insert({x, y, z}); // cout<<val[i][0]<<"\n"; } for(auto i: st) { ans+=i[2]; } cout<<ans; }

Compilation message (stderr)

sirni.cpp: In function 'int32_t main()':
sirni.cpp:51:17: warning: statement has no effect [-Wunused-value]
   51 |             for(l; l<1e7+5; l+=a[i])
      |                 ^
sirni.cpp:57:21: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   57 |                     if((val[val[i][1]][0]>val[i][0]));
      |                     ^~
sirni.cpp:58:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   58 |                     {
      |                     ^
#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...