# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
868197 | borisAngelov | 도서관 (JOI18_library) | C++17 | 53 ms | 948 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "library.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n;
vector<int> g[maxn];
bool visited[maxn];
void Solve(int N)
{
n = N;
int startingNode = -1;
for (int i = 1; i <= n; ++i)
{
int l = 1;
int r = n;
while (l <= r)
{
int mid = (l + r) / 2;
vector<int> takenBooks(n, false);
int cnt = 0;
for (int j = 0; j < mid; ++j)
{
++cnt;
takenBooks[j] = true;
}
int answerWithoutCurrent, answerWithCurrent;
if (takenBooks[i - 1] == true)
{
answerWithCurrent = Query(takenBooks);
takenBooks[i - 1] = false;
--cnt;
answerWithoutCurrent = (cnt == 0 ? 0 : Query(takenBooks));
}
else
{
answerWithoutCurrent = (cnt == 0 ? 0 : Query(takenBooks));
takenBooks[i - 1] = true;
++cnt;
answerWithCurrent = Query(takenBooks);
}
if (answerWithCurrent <= answerWithoutCurrent)
{
r = mid - 1;
}
else
{
l = mid + 1;
}
}
//cout << "connecting " << i << " with " << l << endl;
g[i].push_back(l);
int l2 = l + 1;
int r2 = n;
while (l2 <= r2)
{
int mid = (l2 + r2) / 2;
vector<int> takenBooks(n, false);
int cnt = 0;
for (int j = l; j < mid; ++j)
{
++cnt;
takenBooks[j] = true;
}
int answerWithoutCurrent, answerWithCurrent;
if (takenBooks[i - 1] == true)
{
answerWithCurrent = Query(takenBooks);
takenBooks[i - 1] = false;
--cnt;
answerWithoutCurrent = (cnt == 0 ? 0 : Query(takenBooks));
}
else
{
answerWithoutCurrent = (cnt == 0 ? 0 : Query(takenBooks));
takenBooks[i - 1] = true;
++cnt;
answerWithCurrent = Query(takenBooks);
}
if (answerWithCurrent <= answerWithoutCurrent)
{
r2 = mid - 1;
}
else
{
l2 = mid + 1;
}
}
if (l2 == n + 1)
{
startingNode = i;
}
else
{
//cout << "connecting " << i << " with " << l2 << endl;
g[i].push_back(l2);
}
}
vector<int> ans;
int currentNode = startingNode;
while (ans.size() < n)
{
//cout << "now on " << currentNode << endl;
ans.push_back(currentNode);
visited[currentNode] = true;
for (int i = 0; i < g[currentNode].size(); ++i)
{
int to = g[currentNode][i];
if (visited[to] == false)
{
currentNode = to;
break;
}
}
}
Answer(ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |