Submission #1117906

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
11179062024-11-24 09:37:4412345678Xor Sort (eJOI20_xorsort)C++17
60 / 100
105 ms16244 KiB
#include <bits/stdc++.h>
using namespace std;
const int nx=1e3+5;
int s, n, vs[nx], a[nx];
vector<pair<int, int>> res;
void solve(int sz)
{
pair<int, pair<int, int>> mx;
int cnt=0;
for (int i=1; i<=n; i++) if (!vs[i]) mx=max(mx, {a[i], {i, ++cnt}});
vs[mx.second.first]=1;
//cout<<"debug "<<mx.second.first<<' '<<mx.second.second<<'\n';
cnt=mx.second.second;
for (int i=1; i<sz; i++) res.push_back({i, i+1});
for (int i=cnt; i<sz; i++) res.push_back({i+1, i});
for (int i=cnt-2; i>=1; i--) res.push_back({i, i+1});
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>s;
for (int i=1; i<=n; i++) cin>>a[i];
for (int i=1; i<=n; i++) solve(n-i+1);
for (int i=n-1; i>=1; i--) res.push_back({i, i+1});
cout<<res.size()<<'\n';
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...