답안 #46356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46356 2018-04-19T17:51:04 Z evpipis Sirni (COCI17_sirni) C++11
84 / 140
5000 ms 786436 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef pair<int, int> ii;
typedef long long ll;

const int len = 1e5+2;
int cnt[100*len], nex[100*len][2], p[len], r[len];
list<ii> vec[100*len];

int fin(int i){
    if (p[i] == i) return i;
    return p[i] = fin(p[i]);
}

void join(int i, int j){
    if (r[i] > r[j])
        p[j] = i;
    else{
        p[i] = j;
        if (r[i] == r[j]) r[j]++;
    }
}

void read(int &res){
    char c;
    while (c = getchar(), c < '0' || c > '9'){}
    res = c-'0';
    while (c = getchar(), c >= '0' && c <= '9')
        res = 10*res+c-'0';
}

int main(){
    int n, m = 0, k = 0;
    read(n);
    for (int i = 0; i < n; i++){
        int temp;
        read(temp);

        m = max(m, temp);
        if (!cnt[temp]) cnt[temp] = ++k;
    }

    for (int i = m; i >= 1; i--){
        nex[i][0] = nex[i+1][0];
        if (cnt[i]) nex[i][0] = i;

        nex[i][1] = nex[i+1][1];
        if (cnt[i+1]) nex[i][1] = i+1;
    }

    for (int i = 1; i <= k; i++){
        r[i] = 0;
        p[i] = i;
    }

    for (int i = 1; i <= m; i++)
        if (cnt[i])
            for (int j = i; j <= m; j+=i){
                if (j == i && nex[j][1] && nex[j][1] < j+i)
                    vec[nex[j][1]-j].pb(mp(cnt[i], cnt[nex[j][1]]));
                else if (j != i && nex[j][0] && nex[j][0] < j+i);
                    vec[nex[j][0]-j].pb(mp(cnt[i], cnt[nex[j][0]]));
            }

    ll ans = 0;
    for (int i = 0; i <= m; i++){
        if (k == 1) break;
        for (auto it : vec[i]){
            if (k == 1) break;
            int x = fin(it.fi), y = fin(it.se);
            if (x != y)
                join(x, y), ans += i, k--;
        }
    }

    printf("%lld\n", ans);
    return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:66:22: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
                 else if (j != i && nex[j][0] && nex[j][0] < j+i);
                      ^~
sirni.cpp:67:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
                     vec[nex[j][0]-j].pb(mp(cnt[i], cnt[nex[j][0]]));
                     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 309 ms 317432 KB Output is correct
2 Correct 1288 ms 401904 KB Output is correct
3 Correct 287 ms 401904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 190 ms 401904 KB Output is correct
2 Runtime error 3518 ms 786432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 786432 KB Output is correct
2 Correct 285 ms 786432 KB Output is correct
3 Correct 279 ms 786432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 519 ms 786432 KB Output is correct
2 Correct 1600 ms 786432 KB Output is correct
3 Correct 675 ms 786432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 786432 KB Output is correct
2 Correct 909 ms 786432 KB Output is correct
3 Correct 436 ms 786432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 946 ms 786432 KB Output is correct
2 Correct 1763 ms 786432 KB Output is correct
3 Correct 632 ms 786432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 786432 KB Output is correct
2 Correct 1828 ms 786432 KB Output is correct
3 Correct 621 ms 786432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 940 ms 786432 KB Output is correct
2 Execution timed out 5151 ms 786436 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1085 ms 786436 KB Output is correct
2 Runtime error 4828 ms 786436 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 407 ms 786436 KB Output is correct
2 Execution timed out 5098 ms 786436 KB Time limit exceeded
3 Halted 0 ms 0 KB -