Submission #1167691

#TimeUsernameProblemLanguageResultExecution timeMemory
1167691TurkhuuSirni (COCI17_sirni)C++20
Compilation error
0 ms0 KiB
//https://codeforces.com/blog/entry/50241?#comment-341952 #include<bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for(int i = x; i < (int)(n); ++i) int x[100000], nxt[10000001], p[10000001]; vector<pair<int, int> > w[10000001]; int P(int v){ if (p[v])return p[v] = P(p[v]); return v; } int main(){ int n; scanf("%d", &n); f(i, 0, n)scanf("%d", x + i), nxt[x[i]] = x[i]; sort(x, x + n); n = unique(x, x + n) - x; for (int i = 9999999; i >= 0; --i)if (!nxt[i])nxt[i] = nxt[i + 1]; f(i, 0, n){ int t = x[i], z = nxt[t + 1]; if (z && z - t < t)w[z - t].push_back(make_pair(t, z)); for (int j = t << 1; j <= 10000000; j += t){ z = nxt[j]; if (!z)break; if (z - j < t)w[z - j].push_back(make_pair(t, z)); } } ll an = 0; int k = 0; f(i, 0, 10000000){ vector<pair<int, int> > &v = w[i]; int s = v.size(); f(j, 0, s){ int x = P(v[j].first), y = P(v[j].second); if (x == y)continue; an += i; p[y] = x; if (++k + 1 == n)break; } if (k + 1 == n)break; } printf("%lld\n", an); }#include<bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for(int i = x; i < (int)(n); ++i) int x[100000], nxt[10000001], p[10000001]; vector<pair<int, int> > w[10000001]; int P(int v){ if (p[v])return p[v] = P(p[v]); return v; } int main(){ int n; scanf("%d", &n); f(i, 0, n)scanf("%d", x + i), nxt[x[i]] = x[i]; sort(x, x + n); n = unique(x, x + n) - x; for (int i = 9999999; i >= 0; --i)if (!nxt[i])nxt[i] = nxt[i + 1]; f(i, 0, n){ int t = x[i], z = nxt[t + 1]; if (z && z - t < t)w[z - t].push_back(make_pair(t, z)); for (int j = t << 1; j <= 10000000; j += t){ z = nxt[j]; if (!z)break; if (z - j < t)w[z - j].push_back(make_pair(t, z)); } } ll an = 0; int k = 0; f(i, 0, 10000000){ vector<pair<int, int> > &v = w[i]; int s = v.size(); f(j, 0, s){ int x = P(v[j].first), y = P(v[j].second); if (x == y)continue; an += i; p[y] = x; if (++k + 1 == n)break; } if (k + 1 == n)break; } printf("%lld\n", an); }

Compilation message (stderr)

sirni.cpp:46:2: error: stray '#' in program
   46 | }#include<bits/stdc++.h>
      |  ^
sirni.cpp:46:11: error: 'bits' was not declared in this scope
   46 | }#include<bits/stdc++.h>
      |           ^~~~
sirni.cpp:46:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
   46 | }#include<bits/stdc++.h>
      |                ^~~~
      |                std
sirni.cpp:46:11: error: 'bits' was not declared in this scope
   46 | }#include<bits/stdc++.h>
      |           ^~~~
sirni.cpp:46:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
   46 | }#include<bits/stdc++.h>
      |                ^~~~
      |                std
sirni.cpp:46:11: error: 'bits' was not declared in this scope
   46 | }#include<bits/stdc++.h>
      |           ^~~~
sirni.cpp:46:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
   46 | }#include<bits/stdc++.h>
      |                ^~~~
      |                std
sirni.cpp:46:11: error: 'bits' was not declared in this scope
   46 | }#include<bits/stdc++.h>
      |           ^~~~
sirni.cpp:46:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
   46 | }#include<bits/stdc++.h>
      |                ^~~~
      |                std
sirni.cpp:46:11: error: 'bits' was not declared in this scope
   46 | }#include<bits/stdc++.h>
      |           ^~~~
sirni.cpp:46:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
   46 | }#include<bits/stdc++.h>
      |                ^~~~
      |                std
sirni.cpp:46:11: error: 'bits' was not declared in this scope
   46 | }#include<bits/stdc++.h>
      |           ^~~~
sirni.cpp:46:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
   46 | }#include<bits/stdc++.h>
      |                ^~~~
      |                std
sirni.cpp:46:11: error: 'bits' was not declared in this scope
   46 | }#include<bits/stdc++.h>
      |           ^~~~
sirni.cpp:46:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
   46 | }#include<bits/stdc++.h>
      |                ^~~~
      |                std
sirni.cpp:46:11: error: 'bits' was not declared in this scope
   46 | }#include<bits/stdc++.h>
      |           ^~~~
sirni.cpp:46:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
   46 | }#include<bits/stdc++.h>
      |                ^~~~
      |                std
sirni.cpp:46:11: error: 'bits' was not declared in this scope
   46 | }#include<bits/stdc++.h>
      |           ^~~~
sirni.cpp:46:16: error: 'stdc' was not declared in this scope; did you mean 'std'?
   46 | }#include<bits/stdc++.h>
      |                ^~~~
      |                std
sirni.cpp:46:3: error: 'include' does not name a type
   46 | }#include<bits/stdc++.h>
      |   ^~~~~~~
sirni.cpp:51:5: error: redefinition of 'int x [100000]'
   51 | int x[100000], nxt[10000001], p[10000001];
      |     ^
sirni.cpp:7:5: note: 'int x [100000]' previously declared here
    7 | int x[100000], nxt[10000001], p[10000001];
      |     ^
sirni.cpp:51:16: error: redefinition of 'int nxt [10000001]'
   51 | int x[100000], nxt[10000001], p[10000001];
      |                ^~~
sirni.cpp:7:16: note: 'int nxt [10000001]' previously declared here
    7 | int x[100000], nxt[10000001], p[10000001];
      |                ^~~
sirni.cpp:51:31: error: redefinition of 'int p [10000001]'
   51 | int x[100000], nxt[10000001], p[10000001];
      |                               ^
sirni.cpp:7:31: note: 'int p [10000001]' previously declared here
    7 | int x[100000], nxt[10000001], p[10000001];
      |                               ^
sirni.cpp:52:25: error: redefinition of 'std::vector<std::pair<int, int> > w [10000001]'
   52 | vector<pair<int, int> > w[10000001];
      |                         ^
sirni.cpp:8:25: note: 'std::vector<std::pair<int, int> > w [10000001]' previously declared here
    8 | vector<pair<int, int> > w[10000001];
      |                         ^
sirni.cpp:54:5: error: redefinition of 'int P(int)'
   54 | int P(int v){
      |     ^
sirni.cpp:10:5: note: 'int P(int)' previously defined here
   10 | int P(int v){
      |     ^
sirni.cpp:59:5: error: redefinition of 'int main()'
   59 | int main(){
      |     ^~~~
sirni.cpp:15:5: note: 'int main()' previously defined here
   15 | int main(){
      |     ^~~~
sirni.cpp: In function 'int main()':
sirni.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
sirni.cpp:18:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     f(i, 0, n)scanf("%d", x + i), nxt[x[i]] = x[i];
      |               ~~~~~^~~~~~~~~~~~~
sirni.cpp: In function 'int main()':
sirni.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
sirni.cpp:62:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     f(i, 0, n)scanf("%d", x + i), nxt[x[i]] = x[i];
      |               ~~~~~^~~~~~~~~~~~~