답안 #147597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147597 2019-08-30T08:51:30 Z nicolaalexandra Sirni (COCI17_sirni) C++14
0 / 140
94 ms 7508 KB
#include <iostream>
#include <algorithm>
#include <vector>
#define DIM 100010
using namespace std;
//ifstream fin ("date.in");
//ofstream fout ("date.out");
struct idk{
    int x,y,cost;
};
vector <idk> mch;
int n,i,j,k,last,maxi,nr;
int v[DIM],t[DIM],poz[DIM];

inline int cmp (idk a, idk b){
    return a.cost < b.cost;
}
inline int rad (int x){
    while (t[x] > 0)
        x = t[x];
    return x;
}

int main (){

    cin>>n;
    for (i=1;i<=n;i++){
        cin>>v[i];
        maxi = max (maxi,v[i]);
    }
    sort (v+1,v+n+1);
    k = 1;
    for (i=2;i<=n;i++)
        if (v[i] != v[i-1])
            v[++k] = v[i];
    for (i=1;i<=n;i++)
        poz[v[i]] = i;
    n = k;
    for (i=1;i<=n;i++){
        int last = i+1;
        if (i < n){
            int r = min (v[i]%v[i+1],v[i+1]%v[i]);
            mch.push_back({i,i+1,r});
        }
        for (j=v[i]+v[i];j<=maxi;j+=v[i]){
            if (poz[j]){ /// e in sir
                if (last != poz[j]){
                    int r = min (v[i]%j,j%v[i]);
                    mch.push_back({i,poz[j],r});
                    last = poz[j];
                }
            } else {
                int st = 1, dr = n, val = j;
                while (st <= dr){
                    int mid = (st+dr)>>1;
                    if (v[mid] >= val){
                        dr = mid-1;
                        nr = mid;
                    } else st = mid+1;
                }
                if (last != nr){
                    int r = min (v[i]%v[nr],v[nr]%v[i]);
                    mch.push_back({i,nr,r});
                    last = nr;
                }}}}
    sort (mch.begin(),mch.end(),cmp);
    for (i=1;i<=n;i++)
        t[i] = -1;
    int sol = 0;
    for (int i=0;i<mch.size();i++){
        int x = mch[i].x, y = mch[i].y;
        int rx = rad(x), ry = rad(y);
        if (rx != ry){
            sol += mch[i].cost;
            if (t[rx] < t[ry]){
                t[rx] += t[ry];
                t[ry] = rx;
            } else {
                t[ry] += t[rx];
                t[rx] = ry;
            }}}
    cout<<sol;

    return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:70:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<mch.size();i++){
                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 68 ms 2936 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 2808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 72 ms 2832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 7508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 73 ms 2852 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 75 ms 2772 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 19 ms 2620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -