Submission #481163

#TimeUsernameProblemLanguageResultExecution timeMemory
481163glomeArranging Shoes (IOI19_shoes)C++17
65 / 100
1088 ms11204 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; bool jk = 1; set<int> s2; for (int i = 0; i<s.size(); i++) { s2.insert(s[i]); } if(s2.size() != 2) { jk = 0; } if(s.size() <= 20000 || jk) { 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; } }

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:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for (int i = 0; i<s.size(); i++) {
      |                  ~^~~~~~~~~
shoes.cpp:30:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |    for (int i = 0; i<s.size(); i+=2) {
      |                    ~^~~~~~~~~
shoes.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |      for (int j = i + 1; j<s.size(); j++) {
      |                          ~^~~~~~~~~
shoes.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |        for (int k = 0; k<s.size(); k++) {
      |                        ~^~~~~~~~~
shoes.cpp:52:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |      for (int j = i + 1; j<s.size(); j++) {
      |                          ~^~~~~~~~~
shoes.cpp:55:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |        for (int k = 0; k<s.size(); k++) {
      |                        ~^~~~~~~~~
shoes.cpp:75:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for (int i = 0; i<s.size() / 2; i++) {
      |                  ~^~~~~~~~~~~~~
shoes.cpp:19:11: warning: control reaches end of non-void function [-Wreturn-type]
   19 |  set<int> s2;
      |           ^~
#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...