Submission #483159

#TimeUsernameProblemLanguageResultExecution timeMemory
483159KazamaHoangSirni (COCI17_sirni)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define INF 1000000000 #define M 1000000007 #define ll long long #define MAX 10000001 using namespace std; int a[MAX],m[MAX]; int par[MAX],rank[MAX]; int getroot(int x){ if (par[x]==x) return x; else return getroot(par[x]); } int union_(int x,int y){ int rx = getroot(x); int ry = getroot(y); if (rx==ry) return 0; if (rank[rx]>rank[ry]){ par[ry] = rx; rank[rx]++; } else{ par[rx] = ry; rank[ry]++; } return 0; } int main(){ int n; cin >> n; for (int i=0;i<n;i++){ int x;scanf("%d",&x); m[x] = 1; } n = 0; for (int i=1;i<MAX;i++){ if (m[i]){ a[n++] = i; par[i] = i; } } int groups = n; int md = 0; ll sum = 0; while(groups!=1){ for (int i=0;i<n;i++){ for (int j=a[i]+md;j<MAX;j+=a[i]){ if (m[j] && getroot(a[i])!=getroot(j)){ union_(j,a[i]); sum+=md; groups--; } } } md++; } cout << sum << endl; return 0; }

Compilation message (stderr)

sirni.cpp: In function 'int union_(int, int)':
sirni.cpp:20:6: error: reference to 'rank' is ambiguous
   20 |  if (rank[rx]>rank[ry]){
      |      ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sirni.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
sirni.cpp:9:14: note:                 'int rank [10000001]'
    9 | int par[MAX],rank[MAX];
      |              ^~~~
sirni.cpp:20:15: error: reference to 'rank' is ambiguous
   20 |  if (rank[rx]>rank[ry]){
      |               ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sirni.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
sirni.cpp:9:14: note:                 'int rank [10000001]'
    9 | int par[MAX],rank[MAX];
      |              ^~~~
sirni.cpp:22:3: error: reference to 'rank' is ambiguous
   22 |   rank[rx]++;
      |   ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sirni.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
sirni.cpp:9:14: note:                 'int rank [10000001]'
    9 | int par[MAX],rank[MAX];
      |              ^~~~
sirni.cpp:26:3: error: reference to 'rank' is ambiguous
   26 |   rank[ry]++;
      |   ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sirni.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
sirni.cpp:9:14: note:                 'int rank [10000001]'
    9 | int par[MAX],rank[MAX];
      |              ^~~~
sirni.cpp: In function 'int main()':
sirni.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   int x;scanf("%d",&x);
      |         ~~~~~^~~~~~~~~