답안 #489566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489566 2021-11-23T09:05:43 Z Yuisuyuno Sirni (COCI17_sirni) C++14
140 / 140
1823 ms 770936 KB
//Nguyen Huu Hoang Minh
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define reset(x) memset(x, 0,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define N 100005
#define remain(x) if (x > MOD) x -= MOD
#define ii pair<int, int>
#define iiii pair< ii , ii >
#define viiii vector< iiii >
#define vi vector<int>
#define vii vector< ii >
#define bit(x, i) (((x) >> (i)) & 1)
#define Task "test"
#define int long long

using namespace std;

typedef long double ld;
const int inf = 1e10;
const int M = 1e7+5;
const int minf = -1e10;

int n;
vector<int> p;
int par[N];
int near[M];
bool flag[M];
vector<ii> edge[M];

int get(int u){
    return (par[u]==u ? u : par[u] = get(par[u]));
}

int join(int u, int v){
    u = get(u);
    v = get(v);
    if (u==v) return 0;
    par[v] = u;
    return 1;
}

void readfile()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    if (fopen(Task".inp","r"))
    {
        freopen(Task".inp","r",stdin);
        //freopen(Task".out","w",stdout);
    }
    cin >> n;
    p.resize(n);
    for(auto &x : p) cin >> x;
    sort(all(p));
    p.resize(unique(all(p))-p.begin());
}

void proc()
{
    for(int i=0; i<n; i++) par[i] = i;
    int ans = 0;
    memset(near, 0x3f, sizeof near);
    for(int i=0; i<p.size(); i++) near[p[i]] = i;
    for(int i=p.back(); i>=0; i--) near[i] = min(near[i],near[i+1]);
    for(int i=0; i<p.size()-1; i++){
        int weight = p[near[p[i]+1]]-p[i];

        edge[weight].pb(ii(i,near[p[i]+1]));

        if (!flag[p[i]]) for(int j=2*p[i]; j<=p.back(); j+=p[i]){
            flag[j] = true;
            edge[p[near[j]]-j].pb(ii(i,near[j]));
        }
    }
    for(int i=0; i<1e7+1; i++){
        for(auto tmp : edge[i]){
            ans += join(tmp.fi,tmp.se)*i;
        }
    }
    cout << ans;
}

signed main()
{
    readfile();
    proc();
    return 0;
}

Compilation message

sirni.cpp: In function 'void proc()':
sirni.cpp:68:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i=0; i<p.size(); i++) near[p[i]] = i;
      |                  ~^~~~~~~~~
sirni.cpp:70:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i=0; i<p.size()-1; i++){
      |                  ~^~~~~~~~~~~
sirni.cpp: In function 'void readfile()':
sirni.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen(Task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 321620 KB Output is correct
2 Correct 787 ms 386624 KB Output is correct
3 Correct 215 ms 323836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 194 ms 313520 KB Output is correct
2 Correct 1665 ms 770936 KB Output is correct
3 Correct 218 ms 324712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 322096 KB Output is correct
2 Correct 216 ms 318756 KB Output is correct
3 Correct 227 ms 323408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 330972 KB Output is correct
2 Correct 308 ms 348396 KB Output is correct
3 Correct 299 ms 354004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 318280 KB Output is correct
2 Correct 343 ms 342032 KB Output is correct
3 Correct 228 ms 329780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 306 ms 340996 KB Output is correct
2 Correct 289 ms 355012 KB Output is correct
3 Correct 273 ms 340852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 193 ms 319088 KB Output is correct
2 Correct 332 ms 356072 KB Output is correct
3 Correct 308 ms 353268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 397 ms 349588 KB Output is correct
2 Correct 1061 ms 611772 KB Output is correct
3 Correct 432 ms 355000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 410 ms 356580 KB Output is correct
2 Correct 1556 ms 704064 KB Output is correct
3 Correct 616 ms 463192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 328068 KB Output is correct
2 Correct 1823 ms 637648 KB Output is correct
3 Correct 287 ms 351916 KB Output is correct