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 int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 5e5 + 7;
void print(vector <int> a) {
for (int i = 0; i < a.size(); ++i)
cout << a[i] << ' ';
cout << endl;
}
int get(vector <int> a, int x, int R) {
if (a.size() == 2)
return 0;
//print(a);
for (int t = 0; t < R; ++t) {
for (int i = 0; i < a.size(); i += 2) {
if (a[i] > a[i + 1])
swap(a[i], a[i + 1]);
}
vector <int> b = a;
b[1] = a[2];
for (int i = 4; i < a.size(); i += 2) {
b[i - 2] = a[i];
}
b[(int)b.size() - 2] = a[1];
a = b;
//cout << "new:\n";
//print(a);
}
for (int i = 0; i < a.size(); ++i)
if (a[i] == x)
return i / 2;
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n, R;
cin >> n >> R;
int my;
cin >> my;
vector <int> p(2 * n - 1);
for (int i = 0; i < 2 * n - 1; ++i)
cin >> p[i];
/*
auto t = p;
t.insert(t.begin() + 4, my);
cout << get(t, my, R) << endl;
exit(0);
*/
int ans = N;
int start = -1;
for (int to = 0; to < 2 * n; ++to) {
vector <int> t = p;
t.insert(t.begin() + to, my);
int nn = get(t, my, R);
//cout << to << ' ' << nn << endl;
if (nn <= ans) {
ans = nn;
start = to / 2;
}
}
cout << start + 1 << endl;
}
Compilation message (stderr)
archery.cpp: In function 'void print(std::vector<long long int>)':
archery.cpp:17:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size(); ++i)
~~^~~~~~~~~~
archery.cpp: In function 'long long int get(std::vector<long long int>, long long int, long long int)':
archery.cpp:29:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size(); i += 2) {
~~^~~~~~~~~~
archery.cpp:35:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 4; i < a.size(); i += 2) {
~~^~~~~~~~~~
archery.cpp:45:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size(); ++i)
~~^~~~~~~~~~
archery.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |