#include "swaps.h"
#include <vector>
#include <iostream>
using namespace std;
int N;
int V;
vector<int> r;
void do_comparisons(vector<int> A, vector<int> B)
{
vector<int> a, b;
for(int i = 0; i < A.size(); i++)
{
if(0 <= A[i] && A[i] < N && 0 <= B[i] && B[i] < N)
{
a.push_back(A[i]);
b.push_back(B[i]);
}
}
if(a.size() == 0) return;
for(int i = 0; i < a.size(); i++)
{
schedule(r[ a[i] ], r[ b[i] ]);
}
vector<int> C = visit();
for(int i = 0; i < a.size(); i++)
{
if(C[i] == 0)
swap(r[ a[i] ], r[ a[i] ]);
}
}
void solve(int n, int v)
{
N = n;
V = v;
r = vector<int>(N);
for(int i = 1; i <= N; i++) r[i - 1] = i;
for(int v = 1; v <= min(V, N); v++)
{
vector<int> A, B;
if(v % 2 == 0)
{
for(int i = 0; i+1 < N; i += 2)
{
A.push_back(i);
B.push_back(i+1);
}
}
else
{
for(int i = 1; i+1 < N; i += 2)
{
A.push_back(i);
B.push_back(i+1);
}
}
do_comparisons(A, B);
}
// for(int X = 2; X <= N; X *= 2)
// {
// // cerr << "X = " << X << '\n';
// int p = 0, q = X-1;
// vector<int> A, B;
// while(p < N)
// {
// for(int i = 0; i < X/2; i++)
// {
// if(p + i < N && 0 <= q - i && q - i < N)
// {
// A.push_back(p + i);
// B.push_back(q - i);
// }
// }
//
// p += X;
// q += X;
// }
//
// do_comparisons(A, B);
// A.clear();
// B.clear();
//
//
//
//
// for(int Y = X/2; Y >= 2; Y /= 2)
// {
// for(int i = 0; i + Y/2 < N; i++)
// {
// if((i / (Y/2)) % 2 == 0)
// {
// A.push_back(i);
// B.push_back(i + Y/2);
// }
// }
// do_comparisons(A, B);
// A.clear();
// B.clear();
// }
// }
answer(r);
}
Compilation message
swaps.cpp: In function 'void do_comparisons(std::vector<int>, std::vector<int>)':
swaps.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i = 0; i < A.size(); i++)
| ~~^~~~~~~~~~
swaps.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0; i < a.size(); i++)
| ~~^~~~~~~~~~
swaps.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0; i < a.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
200 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
200 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
4 ms |
200 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
4 ms |
200 KB |
Correct |
3 |
Incorrect |
0 ms |
200 KB |
Not correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
4 ms |
200 KB |
Correct |
3 |
Correct |
18 ms |
276 KB |
Correct |
4 |
Correct |
68 ms |
304 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
4 ms |
200 KB |
Correct |
3 |
Correct |
18 ms |
276 KB |
Correct |
4 |
Correct |
68 ms |
304 KB |
Correct |
5 |
Incorrect |
1 ms |
200 KB |
Not correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
4 ms |
200 KB |
Correct |
3 |
Correct |
16 ms |
200 KB |
Correct |
4 |
Correct |
56 ms |
300 KB |
Correct |
5 |
Correct |
53 ms |
308 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
4 ms |
200 KB |
Correct |
3 |
Correct |
16 ms |
200 KB |
Correct |
4 |
Correct |
56 ms |
300 KB |
Correct |
5 |
Correct |
53 ms |
308 KB |
Correct |
6 |
Incorrect |
1 ms |
200 KB |
Not correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
3 ms |
200 KB |
Correct |
3 |
Correct |
15 ms |
292 KB |
Correct |
4 |
Correct |
64 ms |
412 KB |
Correct |
5 |
Correct |
56 ms |
288 KB |
Correct |
6 |
Incorrect |
11 ms |
284 KB |
Not correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
3 ms |
200 KB |
Correct |
3 |
Correct |
15 ms |
292 KB |
Correct |
4 |
Correct |
64 ms |
412 KB |
Correct |
5 |
Correct |
56 ms |
288 KB |
Correct |
6 |
Incorrect |
11 ms |
284 KB |
Not correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Correct |
2 |
Correct |
4 ms |
200 KB |
Correct |
3 |
Correct |
16 ms |
200 KB |
Correct |
4 |
Correct |
56 ms |
344 KB |
Correct |
5 |
Correct |
57 ms |
304 KB |
Correct |
6 |
Incorrect |
12 ms |
284 KB |
Not correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Correct |
2 |
Correct |
4 ms |
200 KB |
Correct |
3 |
Correct |
16 ms |
200 KB |
Correct |
4 |
Correct |
56 ms |
344 KB |
Correct |
5 |
Correct |
57 ms |
304 KB |
Correct |
6 |
Incorrect |
12 ms |
284 KB |
Not correct |
7 |
Halted |
0 ms |
0 KB |
- |