# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
252337 | SamAnd | Archery (IOI09_archery) | C++17 | 2097 ms | 7672 KiB |
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 <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 400005;
int n, r;
int a[N];
pair<int, int> b[N], bb[N];
void solv1()
{
int ans1 = N, ans2;
for (int u = n; u >= 1; --u)
{
int k = 0;
for (int i = 2; i < u * 2; i += 2)
b[++k] = m_p(a[i], a[i + 1]);
b[++k] = m_p(0, a[u * 2]);
for (int i = u * 2 + 1; i <= n * 2; i += 2)
b[++k] = m_p(a[i], a[i + 1]);
for (int j = 1; j <= 2 * n; ++j)
{
for (int i = 1; i <= n; ++i)
{
if (b[i].first > b[i].second)
{
if (i == 1)
{
bb[i].second = b[i].first;
bb[n].first = b[i].second;
}
else
{
bb[i - 1].first = b[i].first;
bb[i].second = b[i].second;
}
}
else
{
if (i == 1)
{
bb[i].second = b[i].second;
bb[n].first = b[i].first;
}
else
{
bb[i - 1].first = b[i].second;
bb[i].second = b[i].first;
}
}
}
for (int i = 1; i <= n; ++i)
b[i] = bb[i];
}
int t = 0;
for (int i = 1; i <= n; ++i)
{
if (b[i].second == 0)
{
t = i;
break;
}
}
if (!t)
{
for (int i = 1; i <= n; ++i)
{
if (b[i].first == 0)
{
t = (i - 1 - (r - n * 2) % n + n) % n;
++t;
break;
}
}
}
if (t < ans1)
{
ans1 = t;
ans2 = u;
}
if (ans1 == 1)
break;
}
printf("%d\n", ans2);
}
int main()
{
scanf("%d%d", &n, &r);
for (int i = 1; i <= n * 2; ++i)
scanf("%d", &a[i]);
if (a[1] == 1)
{
printf("%d\n", n * 2);
return 0;
}
if (a[1] == n * 2)
{
printf("%d\n", 2);
return 0;
}
for (int i = 2; i <= n * 2; ++i)
{
if (a[i] < a[1])
a[i] = 1;
else
a[i] = -1;
}
a[1] = 0;
solv1();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |