Submission #717945

# Submission time Handle Problem Language Result Execution time Memory
717945 2023-04-02T22:10:43 Z MarwenElarbi Sirni (COCI17_sirni) C++14
84 / 140
2234 ms 786432 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll MOD = 1e9+7;
const int nax = 1e5+5;
const int MAX_VAL = 1e6;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
typedef complex<int> Point;
#define X real()
#define Y imag()
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
vi parent(nax);
int find(int x)
{
    if (x==parent[x]) return x;
    return parent[x]=find(parent[x]);
}
void joinset(int x,int y)
{
    x=find(x);
    y=find(y);
    parent[x]=y;
}
bool sameset(int x,int y)
{
    return find(x)==find(y);
}
int main(){
    optimise;
    // setIO("walk");
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        parent[i]=i;
    }
    set<int> check;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin>>x;
        check.insert(x);
    }
    vi tab;
    for(auto u:check)
    {
        tab.pb(u);
    }
    int mx=tab[tab.size()-1];
    vector<pair<ll,pair<int,int>>> mst;
    for (int i = 0; i < tab.size(); ++i)
    {
        int cur=tab[i];
        while(cur<=mx)
        {
            int r= 0;
            if(cur == tab[i]) r = upper_bound(tab.begin(),tab.end(),cur)-tab.begin();
            else r = lower_bound(tab.begin(),tab.end(),cur)-tab.begin();
            if(r < n){
                mst.pb({tab[r]%tab[i],{i,r}});
                cur+=tab[i];
            } else break;
        }
    }
    sort(mst.begin(),mst.end());
    ll ans=0;
    for (int i = 0; i < mst.size(); ++i)
    {
        int x=mst[i].se.fi;
        int y=mst[i].se.se;
        int z=mst[i].fi;
        if (sameset(x,y)) continue;
        joinset(x,y);
        ans+=z;
    }cout << ans<<endl;
}
  

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (int i = 0; i < tab.size(); ++i)
      |                     ~~^~~~~~~~~~~~
sirni.cpp:94:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for (int i = 0; i < mst.size(); ++i)
      |                     ~~^~~~~~~~~~~~
sirni.cpp: In function 'void setIO(std::string)':
sirni.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 274 ms 66524 KB Output is correct
3 Correct 4 ms 1360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 924 KB Output is correct
2 Runtime error 911 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 2 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 300 ms 38556 KB Output is correct
2 Correct 941 ms 71620 KB Output is correct
3 Correct 460 ms 71072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 5700 KB Output is correct
2 Correct 425 ms 67408 KB Output is correct
3 Correct 273 ms 38300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 583 ms 71388 KB Output is correct
2 Correct 1276 ms 137396 KB Output is correct
3 Correct 393 ms 39092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 10972 KB Output is correct
2 Correct 1237 ms 136416 KB Output is correct
3 Correct 409 ms 38472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 38892 KB Output is correct
2 Runtime error 1743 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 396 ms 38940 KB Output is correct
2 Runtime error 1596 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 6068 KB Output is correct
2 Runtime error 2234 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -