Submission #1045866

#TimeUsernameProblemLanguageResultExecution timeMemory
1045866Sputnik123Arranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "shoes.h" #define ll long long using namespace std; long long count_swaps(vector<ll> s) { int n = s.size() / 2; if(n == 1) { if(s[0] < 0) return 0; return 1; } ll ans = 0; for(ll i = 0; i < n ;i++) ans += i; return ans; } void solve() { ll n; string s; cin >> n >> s; string ans; map <char, ll> mp; for(char i : s) mp[i]++; ll t = 0; for(auto i : mp) t = max(t, i.S); if(t > ((n + 1)/ 2)) { cout << "Impossible" << endl; return; } priority_queue <pair<ll, char>> pq; for(auto i : mp) pq.push({i.second, i.first}); for(ll i = 0 ; i < s.size(); i++) { char res; if(pq.top().first != 0) res = pq.top().second; else res = '!'; ll c = pq.top().first; pq.pop(); if(c != 1) pq.push({c - 1, res}); ans += res; mp[res]--; } // cout << ans << endl; for(ll i = 0; i < ans.size(); i++) { if(ans[i] == '!') { cout << "Impossible" << endl; return; } } map <char, vll> h; for(ll i = 0 ; i < n; i++) h[ans[i]].pb(i); vector <pair<char, ll>> sizes; for(auto i : h) sizes.push_back({i.first, i.second.size()}); sort(all(sizes)); for(ll i = 0; i < n; i++) { if(ans[i] == s[i]) { for(ll j = 0; j < n; j++) if(ans[i] != ans[j] && ans[i] != s[j]) { swap(ans[i], ans[j]); break; } } } // cout << ans << endl; for(ll i = 0; i < n; i++){ if(ans[i] == s[i]) { cout << "Impossible" << endl; return; } } cout << ans << endl; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<long long int>)':
shoes.cpp:9:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    9 |         if(s[0] < 0)    return 0;
      |         ^~
shoes.cpp:10:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   10 |                         return 1;
      |                         ^~~~~~
shoes.cpp: In function 'void solve()':
shoes.cpp:28:22: error: 'struct std::pair<const char, long long int>' has no member named 'S'
   28 |         t = max(t, i.S);
      |                      ^
shoes.cpp:37:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(ll i = 0 ; i < s.size(); i++)
      |                    ~~^~~~~~~~~~
shoes.cpp:52:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(ll i = 0; i < ans.size(); i++)
      |                   ~~^~~~~~~~~~~~
shoes.cpp:60:16: error: 'vll' was not declared in this scope; did you mean 'll'?
   60 |     map <char, vll> h;
      |                ^~~
      |                ll
shoes.cpp:60:19: error: template argument 2 is invalid
   60 |     map <char, vll> h;
      |                   ^
shoes.cpp:60:19: error: template argument 4 is invalid
shoes.cpp:62:10: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type {aka char}]' for array subscript
   62 |         h[ans[i]].pb(i);
      |          ^
shoes.cpp:64:18: error: 'begin' was not declared in this scope
   64 |     for(auto i : h)
      |                  ^
shoes.cpp:64:18: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from shoes.cpp:1:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
shoes.cpp:64:18: error: 'end' was not declared in this scope
   64 |     for(auto i : h)
      |                  ^
shoes.cpp:64:18: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from shoes.cpp:1:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
shoes.cpp:65:51: error: no matching function for call to 'std::vector<std::pair<char, long long int> >::push_back(<brace-enclosed initializer list>)'
   65 |         sizes.push_back({i.first, i.second.size()});
      |                                                   ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from shoes.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<char, long long int>; _Alloc = std::allocator<std::pair<char, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<char, long long 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<char, long long 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<char, long long int>; _Alloc = std::allocator<std::pair<char, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<char, long long 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<char, long long int> >::value_type&&' {aka 'std::pair<char, long long int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
shoes.cpp:66:10: error: 'all' was not declared in this scope; did you mean 'std::filesystem::perms::all'?
   66 |     sort(all(sizes));
      |          ^~~
      |          std::filesystem::perms::all
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/fs_fwd.h:148:7: note: 'std::filesystem::perms::all' declared here
  148 |       all  =  0777,
      |       ^~~