Submission #481162

#TimeUsernameProblemLanguageResultExecution timeMemory
481162glomeArranging Shoes (IOI19_shoes)C++17
65 / 100
810 ms3120 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) { int n = s.size() / 2; 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; } bool ok = 1; for (int i = 0; i<s.size() / 2; i++) { if(-s[i] == s[i+n] && s[i] < 0) { } else { ok = 0; } } if(ok) { return (long long) n * (long long) (n - 1) / 2; } map<int, unordered_set<int>> neg, pos; 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:22:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |    for (int i = 0; i<s.size(); i+=2) {
      |                    ~^~~~~~~~~
shoes.cpp:27:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |      for (int j = i + 1; j<s.size(); j++) {
      |                          ~^~~~~~~~~
shoes.cpp:30:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |        for (int k = 0; k<s.size(); k++) {
      |                        ~^~~~~~~~~
shoes.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |      for (int j = i + 1; j<s.size(); j++) {
      |                          ~^~~~~~~~~
shoes.cpp:47:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |        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() / 2; i++) {
      |                  ~^~~~~~~~~~~~~
shoes.cpp:79:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |  for (int i = 0; i<s.size(); i++) {
      |                  ~^~~~~~~~~
shoes.cpp:88:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |  for (int i = 0; i<s.size(); i++) {
      |                  ~^~~~~~~~~
#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...