//
// --- Sample implementation for the task swaps ---
//
// To compile this program with the sample grader, place:
// swaps.h swaps_sample.cpp sample_grader.cpp
// in a single folder and run:
// g++ swaps_sample.cpp sample_grader.cpp
// in this folder.
//
#include "swaps.h"
using namespace std;
using pii = pair<int, int>;
vector<vector<pii>> comparisons;
void call_in(int i, int j, int round)
{
comparisons[round].push_back({i, j});
}
void group_call_in(int i, int j, int round)
{
int mid = (i+j)/2;
int diff = mid-i+1;
for (int k=i; k<=mid; k++)
call_in(k, k+diff, round);
if ((j-i)>1)
{
group_call_in(i, mid, round+1);
group_call_in(mid+1, j, round+1);
}
}
void sortpow2(int lo, int hi, int major_round)
{
int mid = (lo+hi)/2;
if ((hi-lo)>1)
{
sortpow2(lo, mid, major_round-1);
sortpow2(mid+1, hi, major_round-1);
}
int first_round_in_major_round = ((major_round)*(major_round-1))/2 - 1;
for (int i=lo; i<=mid; i++)
call_in(i, lo+hi-i, first_round_in_major_round);
group_call_in(lo, mid, first_round_in_major_round+1);
group_call_in(mid+1, hi, first_round_in_major_round+1);
}
void init()
{
int K = 512;
comparisons = vector<vector<pii>> (45);
sortpow2(1, 512, 9);
}
void solve(int N, int V) {
init();
for (int i=0; i<45; i++)
{
for (pii x: comparisons[i])
schedule(x.first, x.second);
visit();
}
vector<int> beauty;
for (int i=1; i<=N; i++)
beauty.push_back(i);
answer(beauty);
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |