Submission #268742

# Submission time Handle Problem Language Result Execution time Memory
268742 2020-08-16T23:38:39 Z fivefourthreeone Sirni (COCI17_sirni) C++17
140 / 140
3901 ms 746296 KB
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 100001;
const int mxA = 10000001;
int id[mxA];
int arr[mxA];
vector<int> all;
int n;
vector<ttgl> edges[mxA];
int dsu[mxN];
int find(int a) {
    return a==dsu[a] ? a : dsu[a] = find(dsu[a]);
}
void merge(int a, int b) {
    dsu[find(b)] = find(a);
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    int maxval = 0;
    all.resize(n);
    owo(i, 0, n) {
        cin>>all[i];
        maxval = max(maxval, all[i]);
    }
    owo(i, 0, n) {
        dsu[i] = i;
    }
    sort(all.begin(), all.end());
    all.resize(unique(all.begin(), all.end()) - all.begin());
    n= all.size();
    owo(i, 0, all.size())id[all[i]] = i;
    owo(i, 0, n-1) {
        int nxt = i+1;
        for(int j=all[i]; j<=maxval; j+=all[i]) {
            while(all[nxt]<j)nxt++;
            edges[all[nxt]%all[i]].senpai({i, nxt});
        }
    }
    ll ans = 0;
    owo(i, 0, maxval+1) {
        for(auto p: edges[i]) {
            if(find(p.first)!=find(p.second)) {
                ans+=i;
                merge(p.first, p.second);
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Compilation message

sirni.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
sirni.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
sirni.cpp: In function 'int main()':
sirni.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define owo(i,a, b) for(int i=(a);i<(b); ++i)
      |                                    ^
sirni.cpp:61:5: note: in expansion of macro 'owo'
   61 |     owo(i, 0, all.size())id[all[i]] = i;
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 223 ms 238968 KB Output is correct
2 Correct 318 ms 266744 KB Output is correct
3 Correct 235 ms 239480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 235384 KB Output is correct
2 Correct 1445 ms 630948 KB Output is correct
3 Correct 198 ms 239960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 192 ms 239304 KB Output is correct
2 Correct 199 ms 237624 KB Output is correct
3 Correct 191 ms 239352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1643 ms 250128 KB Output is correct
2 Correct 1619 ms 278348 KB Output is correct
3 Correct 1270 ms 260952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 216 ms 241400 KB Output is correct
2 Correct 340 ms 262392 KB Output is correct
3 Correct 1206 ms 248484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1727 ms 262348 KB Output is correct
2 Correct 1849 ms 296648 KB Output is correct
3 Correct 1602 ms 259084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 416 ms 239940 KB Output is correct
2 Correct 1715 ms 296588 KB Output is correct
3 Correct 1373 ms 260824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1818 ms 288588 KB Output is correct
2 Correct 3130 ms 633904 KB Output is correct
3 Correct 1894 ms 291388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1842 ms 293268 KB Output is correct
2 Correct 3901 ms 746296 KB Output is correct
3 Correct 1969 ms 348900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 283 ms 271792 KB Output is correct
2 Correct 3382 ms 626420 KB Output is correct
3 Correct 1416 ms 263012 KB Output is correct