Submission #1321573

#TimeUsernameProblemLanguageResultExecution timeMemory
1321573orgiloogiiGondola (IOI14_gondola)C++20
Compilation error
0 ms0 KiB
#include "gondola.h" #include <bits/stdc++.h> #define ll long long using namespace std; int valid(int n, int g[]) { ll idx = -1; map <ll, bool> vis; for (ll i = 0;i < n;i++) { if (vis[g[i]] == true) return 0; vis[g[i]] = true; if (g[i] <= n && idx == -1) { idx = i; } } if (idx == -1) return 1; ll cnt = g[idx]; for (ll i = idx + 1;;i++) { i %= n; if (i == idx) break; cnt %= n; cnt++; if (g[i] <= n && g[i] != cnt) return 0; } return 1; } //---------------------- int replacement(int n, int g[], int r[]) { ll idx = -1; map <ll, bool> vis; ll mx = 0; for (ll i = 0;i < n;i++) { if (vis[g[i]] == true) return 0; vis[g[i]] = true; if (g[i] <= n && idx == -1) { idx = i; } mx = max(mx, g[i]); } ll sz = 0; ll exp[n] = {0}; if (idx == -1) { exp[0] = 1; ll cnt = 1; for (ll i = 1;;i++) { i %= n; if (i == 0) break; cnt %= n; cnt++; exp[i] = cnt; } } else { exp[idx] = g[idx]; ll cnt = g[idx]; for (ll i = idx + 1;;i++) { i %= n; if (i == idx) break; cnt %= n; cnt++; exp[i] = cnt; } } // for (ll i = 0;i < n;i++) { // cout << exp[i] << ' '; // } // cout << endl; vector <pair <ll, ll>> upd; for (ll i = 0;i < n;i++) { if (exp[i] != g[i]) { upd.push_back({g[i], exp[i]}); } } sort(upd.begin(), upd.end()); for (auto [x, y] : upd) { r[sz] = y; sz++; for (ll i = n + sz;i < x;i++) { r[sz] = i; sz++; } } return mx - n; } const ll mod = 1e9 + 9; ll poww(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y % 2 == 1) { res = 1LL * res * x % mod; } x = 1LL * x * x % mod; y /= 2; } res = 1LL * res * x % mod; return res; } int countReplacement(int n, int g[]) { if (!valid(n, g)) { return 0; } ll mult = n; vector <ll> saves; for (ll i = 0;i < n;i++) { if (g[i] > n) { saves.push_back(g[i]); } if (g[i] <= n) { mult = 1; } } sort(saves.begin(), saves.end()); ll curr = n; ll sz = saves.size(); ll res = 1; for (ll i = 0;i < saves.size();i++) { ll iter = saves[i] - curr - 1; if (iter == 0) { sz--; curr = saves[i]; continue; } res = (res * poww(sz, iter)) % mod; sz--; curr = saves[i]; } return (res * mult) % mod; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:39:25: error: no matching function for call to 'max(long long int&, int&)'
   39 |                 mx = max(mx, g[i]);
      |                      ~~~^~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from gondola.cpp:2:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
gondola.cpp:39:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   39 |                 mx = max(mx, g[i]);
      |                      ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
gondola.cpp:39:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   39 |                 mx = max(mx, g[i]);
      |                      ~~~^~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
gondola.cpp:39:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |                 mx = max(mx, g[i]);
      |                      ~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
gondola.cpp:39:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |                 mx = max(mx, g[i]);
      |                      ~~~^~~~~~~~~~