제출 #143079

#제출 시각아이디문제언어결과실행 시간메모리
143079model_codeArranging Shoes (IOI19_shoes)C++17
30 / 100
124 ms14888 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; namespace testcaseCheck { const int SUBTASK = 2; bool permutationsOfShoes(vector<int> S, int N) { vector<int> V; for (int i = 1; i <= N; ++i) { V.push_back(-i); V.push_back(i); } sort(S.begin(), S.end()); sort(V.begin(), V.end()); for (int i = 0; i < 2 * N; ++i) { if (S[i] != V[i]) { return false; } } return true; } void run(std::vector<int> S) { assert(1 <= SUBTASK && SUBTASK <= 6); assert(S.size() % 2 == 0); int N = S.size() / 2; assert(1 <= N && N <= 100000); map<int, int> sizeToOccurences; for (int s : S) { sizeToOccurences[abs(s)] += s / abs(s); } for (pair<int, int> occurences : sizeToOccurences) { assert(occurences.second == 0); } if (SUBTASK == 1) { assert(N == 1); } if (SUBTASK == 2) { assert(N <= 8); } if (SUBTASK == 3) { for (int s : S) { assert(abs(s) == abs(S[0])); } } if (SUBTASK == 4) { for (int i = 0; i < N; ++i) { assert(abs(S[i]) == S[i + N]); } } if (SUBTASK == 5) { assert(N <= 1000); } } } // namespace testcaseCheck long long count_swaps(std::vector<int> S) { testcaseCheck::run(S); vector<int> sizes; for (int s : S) { if (s > 0) { sizes.push_back(s); } } int answer = INT_MAX; sort(sizes.begin(), sizes.end()); do { int res = 0; vector<int> currentOrder = S; vector<int> expectedOrder; for (int i = 0; i < sizes.size(); ++i) { expectedOrder.push_back(-sizes[i]); expectedOrder.push_back(sizes[i]); } for (int i = 0; i < expectedOrder.size(); ++i) { for (int j = i; j < currentOrder.size(); ++j) { if (currentOrder[j] == expectedOrder[i]) { while (i != j) { swap(currentOrder[j], currentOrder[j - 1]); --j; ++res; } break; } } } answer = min(answer, res); } while (next_permutation(sizes.begin(), sizes.end())); return answer; }

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:87:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < sizes.size(); ++i) {
                     ~~^~~~~~~~~~~~~~
shoes.cpp:92:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < expectedOrder.size(); ++i) {
                     ~~^~~~~~~~~~~~~~~~~~~~~~
shoes.cpp:93:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = i; j < currentOrder.size(); ++j) {
                       ~~^~~~~~~~~~~~~~~~~~~~~
#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...