답안 #1112485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112485 2024-11-14T08:46:40 Z chaoslong Sirni (COCI17_sirni) C++14
126 / 140
1200 ms 786432 KB
// Calm down.
// Think three times, code twice.
#include "bits/stdc++.h"
#define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <ll,ll>
#define piii pair <int,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

using namespace std;
const int N = 1e7 + 600;
const int mod = 1e9 + 7; // 998244353
const ll oo = 1e18;

int n, par[N], sz[N];
vector<pii> f[N];

int find(int v) {
    if(v == par[v]) return v;
    return par[v] = find(par[v]);
}

bool join(int x, int y) {
    x = find(x); y = find(y);
    if(x != y) {
        if(sz[x] < sz[y]) swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
        return true;
    }
    return false;
}

void to_nho_cau() {
    cin >> n;
    vector<int> a;
    forr(i, 1, n) {
        int x; cin >> x;
        a.pb(x);
    }
    if(a.size()) {
        sort(all(a)); a.resize(unique(all(a)) - a.begin());
    }
    int mx = a.back();
    vector<int> nxt(mx + 500, -1);
    forf(i, 0, a.size()) {
        nxt[a[i]] = i;
    }
    ford(i, mx-1, 0) {
        if(nxt[i] == -1) nxt[i] = nxt[i+1];
    }
    forf(i, 0, a.size()) {
        if(i+1 < a.size())
            f[a[i+1] % a[i]].pb({i, i+1});
        for(int cur = 2 * a[i]; cur <= mx; cur += a[i]) {
            int good = nxt[cur];
            if(good < a.size() && good > i)
                f[a[good] % a[i]].pb({i, good});
        }
    }
//    forf(i, 0, a.size()) {
//        par[a[i]] = a[i];
//        sz[a[i]] = 1;
//    }
    forr(i, 0, mx + 500) {
        par[i] = i;
        sz[i] = 1;
    }
    ll ans = 0;
    forr(i, 0, mx) {
        for(pii e: f[i]) {
            int u = e.st, v = e.nd;
            if(join(u, v)) {
                ans = ans + i;
            }
        }
    }
    cout << ans << "\n";
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef LOCAL
        freopen(file".inp","r",stdin);
        freopen(file".out","w",stdout);
    #endif
    int t = 1;
    //cin >> t;
    while(t--) to_nho_cau();
}
/*
1.self check:
2.long long
3.size of array
4.code for testing
5.initializing
6.modulo number
*/
/**
  ∧__∧
(`•ω• )づ__∧
(つ  /( •ω•。)
  しーJ (nnノ) pat pat
**/
/**  /\_/\
*   (= ._.)
*   / >☕ \>💻
**/

Compilation message

sirni.cpp:118:9: warning: "/*" within comment [-Wcomment]
  118 | /**  /\_/\
      |          
sirni.cpp: In function 'void to_nho_cau()':
sirni.cpp:6:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
      |                                              ^
sirni.cpp:59:5: note: in expansion of macro 'forf'
   59 |     forf(i, 0, a.size()) {
      |     ^~~~
sirni.cpp:6:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
      |                                              ^
sirni.cpp:65:5: note: in expansion of macro 'forf'
   65 |     forf(i, 0, a.size()) {
      |     ^~~~
sirni.cpp:66:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         if(i+1 < a.size())
      |            ~~~~^~~~~~~~~~
sirni.cpp:70:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             if(good < a.size() && good > i)
      |                ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 352584 KB Output is correct
2 Correct 273 ms 381512 KB Output is correct
3 Correct 209 ms 352584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 235336 KB Output is correct
2 Correct 1000 ms 746780 KB Output is correct
3 Correct 206 ms 353552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 208 ms 352840 KB Output is correct
2 Correct 213 ms 352352 KB Output is correct
3 Correct 221 ms 352844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 256948 KB Output is correct
2 Correct 253 ms 284988 KB Output is correct
3 Correct 193 ms 267960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 248936 KB Output is correct
2 Correct 208 ms 270024 KB Output is correct
3 Correct 186 ms 251308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 268180 KB Output is correct
2 Correct 282 ms 302656 KB Output is correct
3 Correct 206 ms 266160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 240944 KB Output is correct
2 Correct 289 ms 304248 KB Output is correct
3 Correct 210 ms 267716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 365840 KB Output is correct
2 Correct 1104 ms 710832 KB Output is correct
3 Correct 300 ms 369656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 278 ms 370368 KB Output is correct
2 Runtime error 1200 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 233 ms 354888 KB Output is correct
2 Correct 1087 ms 712584 KB Output is correct
3 Correct 191 ms 269744 KB Output is correct