Submission #636490

# Submission time Handle Problem Language Result Execution time Memory
636490 2022-08-29T11:04:48 Z berr Sirni (COCI17_sirni) C++17
0 / 140
648 ms 243712 KB
#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

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 time Memory Grader output
1 Incorrect 205 ms 235192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 442 ms 235184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 200 ms 235196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 417 ms 243260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 253 ms 236268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 648 ms 243208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 480 ms 238024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 295 ms 243684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 282 ms 243712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 216 ms 236816 KB Output isn't correct
2 Halted 0 ms 0 KB -