This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "trilib.h"
#include <vector>
#include <algorithm>
#include <iostream>
#define int int64_t
using namespace std;
signed main()
{
int n = get_n();
vector<int> next(n, -1);
vector<int> prev(n, -1);
if (is_clockwise(1, 2, 3))
{
next[0] = 1;
next[1] = 2;
next[2] = 0;
prev[0] = 2;
prev[1] = 0;
prev[2] = 1;
}
else
{
next[0] = 2;
next[1] = 0;
next[2] = 1;
prev[0] = 1;
prev[1] = 2;
prev[2] = 0;
}
int start = 0;
for (int i = 3; i < n; i++)
{
int curr = -1;
while (curr != start)
{
if (curr == -1)
{
curr = start;
}
bool cl = is_clockwise(curr + 1, i + 1, next[curr] + 1);
if (cl)
{
next[i] = next[curr];
next[curr] = i;
prev[i] = curr;
prev[next[i]] = i;
while (true)
{
if (is_clockwise(i + 1, next[i] + 1, next[next[i]] + 1)) break;
else
{
int old = next[i];
next[i] = next[next[i]];
next[old] = -1;
prev[next[i]] = i;
prev[old] = -1;
if (old == start) start = i;
}
}
while (true)
{
if (!is_clockwise(i + 1, prev[i] + 1, prev[prev[i]] + 1)) break;
else
{
int old = prev[i];
prev[i] = prev[prev[i]];
prev[old] = -1;
next[prev[i]] = i;
next[old] = -1;
if (old == start) start = i;
}
}
break;
}
else
{
curr = next[curr];
}
}
/*
cout << i << ":\n";
int cn = -1;
while (cn != start)
{
if (cn == -1) cn = start;
cout << cn << " ";
cn = next[cn];
}
cout << "\n";
*/
}
int res = 0;
for (int i : next)
{
if (i != -1) res++;
}
give_answer(res);
}
# | 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... |