// #pragma GCC optimize("Ofast,unroll-loops")
#ifdef MINHDEPTRAI
#include "/Library/Developer/CommandLineTools/usr/include/c++/v1/bits/stdc++.h"
#include <chrono>
#define __gcd(a, b) gcd(a, b)
using namespace std ::chrono;
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define foru(i, a, b) for (int i = a; i <= b; ++i)
#define ford(i, a, b) for (int i = a; i >= b; --i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp(a, b) make_pair(a, b)
// #define int long long
typedef pair<int, int> pii;
typedef pair<pair<int, int>, int> piii;
#define endl '\n'
const string name_minh = "9";
#define int long long
const int maxN = 2e5 + 5;
const int mod = 1;
const int inf = 1e9;
int n, arr[maxN], k;
vector<pair<int, int>> ans;
void push_arr(int i, int j){
ans.push_back(mp(j, i));
ans.push_back(mp(i, j));
ans.push_back(mp(j, i));
}
void solve(){
cin >> n >> k;
foru(i, 1, n){
cin >> arr[i];
}
bool swapped = true;
int start = 1, end = n;
while(swapped){
swapped = false;
foru(i, start, end - 1){
if(arr[i] > arr[i + 1]){
swap(arr[i], arr[i + 1]);
push_arr(i + 1, i);
swapped = true;
}
}
if(!swapped) break;
end--;
swapped = false;
ford(i, end, start + 1){
if(arr[i] < arr[i - 1]){
swap(arr[i], arr[i - 1]);
push_arr(i, i - 1);
swapped = true;
}
}
start++;
}
cout << ans.size() << endl;
for(auto x: ans){
cout << x.first << " " << x.second << endl;
}
}
signed main(){
IOS
// #ifdef MINHDEPTRAI
// ifstream cin(name_minh + ".in");
// ofstream cout(name_minh + ".out");
// #endif
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
728 KB |
Output is correct |
5 |
Correct |
3 ms |
972 KB |
Output is correct |
6 |
Correct |
3 ms |
984 KB |
Output is correct |
7 |
Correct |
4 ms |
972 KB |
Output is correct |
8 |
Correct |
3 ms |
984 KB |
Output is correct |
9 |
Correct |
4 ms |
984 KB |
Output is correct |
10 |
Correct |
3 ms |
1004 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1492 KB |
Output is correct |
13 |
Correct |
7 ms |
1492 KB |
Output is correct |
14 |
Correct |
5 ms |
1492 KB |
Output is correct |
15 |
Correct |
7 ms |
1480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
728 KB |
Output is correct |
5 |
Correct |
3 ms |
972 KB |
Output is correct |
6 |
Correct |
3 ms |
984 KB |
Output is correct |
7 |
Correct |
4 ms |
972 KB |
Output is correct |
8 |
Correct |
3 ms |
984 KB |
Output is correct |
9 |
Correct |
4 ms |
984 KB |
Output is correct |
10 |
Correct |
3 ms |
1004 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1492 KB |
Output is correct |
13 |
Correct |
7 ms |
1492 KB |
Output is correct |
14 |
Correct |
5 ms |
1492 KB |
Output is correct |
15 |
Correct |
7 ms |
1480 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
968 KB |
Output is correct |
18 |
Correct |
4 ms |
1108 KB |
Output is correct |
19 |
Correct |
4 ms |
1108 KB |
Output is correct |
20 |
Correct |
4 ms |
1096 KB |
Output is correct |
21 |
Correct |
6 ms |
1108 KB |
Output is correct |
22 |
Correct |
5 ms |
1108 KB |
Output is correct |
23 |
Correct |
6 ms |
1108 KB |
Output is correct |
24 |
Correct |
4 ms |
1108 KB |
Output is correct |
25 |
Correct |
5 ms |
1108 KB |
Output is correct |
26 |
Incorrect |
10 ms |
1808 KB |
Integer 59568 violates the range [0, 40000] |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
1092 KB |
Output is correct |
5 |
Incorrect |
122 ms |
18544 KB |
Integer 764742 violates the range [0, 40000] |
6 |
Halted |
0 ms |
0 KB |
- |