Submission #481154

#TimeUsernameProblemLanguageResultExecution timeMemory
481154glomeArranging Shoes (IOI19_shoes)C++17
50 / 100
798 ms53192 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; bool check(vector<int> s) { for (int i = 0; i<s.size(); i+=2) { if(s[i] > 0 || -s[i] != s[i+1]) { return 0; } } return 1; } long long count_swaps(std::vector<int> s) { if(s.size() <= 20000) { long long ans = 0; while(!check(s)) { vector<int> news; for (int i = 0; i<s.size(); i+=2) { if(-s[i] == s[i + 1] && s[i] < 0) { continue; } if(s[i] < 0) { for (int j = i + 1; j<s.size(); j++) { if(s[j] == -s[i]) { ans += abs((i + 1) - j); for (int k = 0; k<s.size(); k++) { if(k == j) { continue; } if(k == i + 1) { news.push_back(s[j]); } news.push_back(s[k]); } break; } } } else { for (int j = i + 1; j<s.size(); j++) { if(s[j] == -s[i]) { ans += abs(i - j); for (int k = 0; k<s.size(); k++) { if(k == j) { continue; } if(k == i) { news.push_back(s[j]); } news.push_back(s[k]); } break; } } } break; } s = news; } return ans; } map<int, unordered_set<int>> neg, pos; int n = s.size() >> 1; for (int i = 0; i<s.size(); i++) { if(i < 0) { neg[s[i]].insert(i); } else { pos[s[i]].insert(i); } } long long ans = 0; for (int i = 0; i<s.size(); i++) { if(-s[i] == s[i+1]) { i++; continue; } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'bool check(std::vector<int>)':
shoes.cpp:8:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for (int i = 0; i<s.size(); i+=2) {
      |                  ~^~~~~~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:21:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |    for (int i = 0; i<s.size(); i+=2) {
      |                    ~^~~~~~~~~
shoes.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |      for (int j = i + 1; j<s.size(); j++) {
      |                          ~^~~~~~~~~
shoes.cpp:29:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |        for (int k = 0; k<s.size(); k++) {
      |                        ~^~~~~~~~~
shoes.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |      for (int j = i + 1; j<s.size(); j++) {
      |                          ~^~~~~~~~~
shoes.cpp:46:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |        for (int k = 0; k<s.size(); k++) {
      |                        ~^~~~~~~~~
shoes.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for (int i = 0; i<s.size(); i++) {
      |                  ~^~~~~~~~~
shoes.cpp:76:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |  for (int i = 0; i<s.size(); i++) {
      |                  ~^~~~~~~~~
shoes.cpp:66:6: warning: unused variable 'n' [-Wunused-variable]
   66 |  int n = s.size() >> 1;
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...