#include "unique.h"
std::vector<int> PickUnique(int N) {
std::vector<int> answer(N, 0);
// Iterate: prefix[i]: [0~i], suffix[i]: [i~end)
std::vector<int> prefixUniqueCount(N, 0), suffixUniqueCount(N, 0);
for(int left=0; left<N-1; left++){
suffixUniqueCount[left] = UniqueCount(left, N-1);
prefixUniqueCount[left+1] = UniqueCount(0, left+1);
}
prefixUniqueCount[0] = 1; suffixUniqueCount.back() = 1;
for(int mid=0; mid<N; mid++){
bool left = false, right = false;
// Left
if(mid == 0) left = true;
else if(prefixUniqueCount[mid-1] == prefixUniqueCount[mid] - 1) left = true;
// Right
if(mid == N-1) right = true;
else if(suffixUniqueCount[right+1] == suffixUniqueCount[right] - 1) right = true;
answer[mid] = (int)(left && right);
}
return answer;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Correct : C = 2 |
2 |
Incorrect |
5 ms |
256 KB |
Wrong |
3 |
Halted |
0 ms |
0 KB |
- |