# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1032549 | omarpaladines95 | Arranging Shoes (IOI19_shoes) | C++14 | 1099 ms | 3896 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
void FindFirstSwap(std::vector<int>& original_copy, const std::vector<int>& target, int& startingIndex, long long& numSwaps)
{
int i = 0;
int j = 0;
startingIndex = target.size();
while (original_copy[i] == target[j])
{
++i;
++j;
// If we reached the end and they match, we can just return.
if ((i == target.size()) && (j == target.size()))
{
break;
}
}
// Now we need to advance i until it matches.
for (int start = i; start < target.size(); ++start)
{
if(target[j] == original_copy[start])
{
i=start;
break;
}
}
startingIndex = i;
numSwaps = i-j;
}
long long FindNumberOfSwaps(const std::vector<int>& original, const std::vector<int>& target)
{
long long totalSwaps = 0;
std::vector<int> original_copy = original;
// We will keep modifying original_copy until we swap everything.
while (true)
{
int startingIndex = target.size();
long long numSwaps = 0;
FindFirstSwap(original_copy, target, startingIndex, numSwaps);
totalSwaps += numSwaps;
if (startingIndex == target.size())
{
break;
}
else
{
// Apply the swaps.
for (int i = 0; i < numSwaps; ++i)
{
int localCopy = original_copy[startingIndex];
original_copy[startingIndex] = original_copy[startingIndex-1];
original_copy[startingIndex - 1] = localCopy;
startingIndex--;
}
}
}
return totalSwaps;
}
bool IsValid(const std::vector<int>& curPermutation)
{
for (int i = 0; i < curPermutation.size(); i+=2)
{
if(!((curPermutation[i] < 0) && (curPermutation[i+1] > 0) && ((curPermutation[i] + curPermutation[i+1]) == 0)))
{
return false;
}
}
return true;
}
long long count_swaps(std::vector<int> S)
{
long long minSwaps = LLONG_MAX;
vector<int> curPermutation = S;
sort(curPermutation.begin(), curPermutation.end());
do
{
if (IsValid(curPermutation))
{
minSwaps = min(minSwaps, FindNumberOfSwaps(S, curPermutation));
}
} while(next_permutation(curPermutation.begin(), curPermutation.end()));
return minSwaps;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |