Submission #582983

#TimeUsernameProblemLanguageResultExecution timeMemory
582983NintsiChkhaidzeSirni (COCI17_sirni)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> //#include <iostream> //#include <vector> #define s second #define pb push_back #define f first using namespace std; const int N = 100005,M = 10000005; int p[N],a[N]],ans; int m[M]; vector <pair<int,pair<int,int> > > edges; vector <pair<int,int> > d; int P(int x){ if (x == p[x]) return x; return p[x] = P(p[x]); } void dsu(int a,int b,int c){ int pa = P(a),pb = P(b); if (pa == pb) return; ans += c; if (pa < pb) swap(pa,pb); p[pb] = pa; } int main() { ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n; cin>>n; for (int i = 1; i <= n; i++) cin>>a[i],p[i] = i,d.pb({a[i],i}); sort(d.begin(),d.end()); int r = d.size() - 1; m[10000001] = -1; for (int i = 1e7; i >= 1; i--){ m[i] = m[i + 1]; while (r >= 0 && i <= d[r].f) m[i] = r,r--; } for (int y = 0; y < n; y++){ if (y > 0 && d[y].f == d[y - 1].f) edges.pb({0,{y,y - 1}}); if (y + 1 < n) edges.pb({d[y+1].f - d[y].f,{y,y + 1}}); if (y > 0 && d[y].f == d[y - 1].f) continue; for (int j = d[y].f; j <= 1e7; j += d[y].f){ if (m[j] < 0) continue; if (d[m[j]].f - j < d[y].f) edges.pb({d[m[j]].f - j,{y,m[j]}}); } } sort(edges.begin(),edges.end()); for (int i=0;i<edges.size();i++){ int x = edges[i].s.f,y = edges[i].s.s,c = edges[i].f; dsu(x,y,c); } cout<<ans; }

Compilation message (stderr)

sirni.cpp:10:14: error: expected initializer before ']' token
   10 | int p[N],a[N]],ans;
      |              ^
sirni.cpp: In function 'void dsu(int, int, int)':
sirni.cpp:24:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   24 |     ans += c;
      |     ^~~
      |     abs
sirni.cpp: In function 'int main()':
sirni.cpp:34:14: error: 'a' was not declared in this scope
   34 |         cin>>a[i],p[i] = i,d.pb({a[i],i});
      |              ^
sirni.cpp:34:41: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   34 |         cin>>a[i],p[i] = i,d.pb({a[i],i});
      |                                         ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from sirni.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
sirni.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i=0;i<edges.size();i++){
      |                  ~^~~~~~~~~~~~~
sirni.cpp:64:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   64 |     cout<<ans;
      |           ^~~
      |           abs