답안 #633796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633796 2022-08-23T09:09:14 Z devvops Xor Sort (eJOI20_xorsort) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define int long long
#define ull unsigned long long
#define all(x) x.begin(), x.end() 
#define speed ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define file freopen("palindrome.in", "r", stdin), freopen("palindrome.out", "w", stdout);
const int N = (int) 5 * 1e5, inf = INT_MAX;
int a[2000], b[2000];
main() {
    speed;
   	int n, S;
   	cin >> n >> S;
   	vector<pair<int, int>> v;
   	for(int i = 1; i <= n; i++){
   		cin >> a[i];
   		b[i] = a[i];
   	}
   	sort(b + 1, b + 1 + n);
   	for(int i = n; i >= 1; i--){
   		if(b[i] == a[i]){
   			continue;
   		}
   		int x;
   		for(int j = 1; j <= n; j++){
   			if(a[j] == b[i]){
   				x = j;
   				break;
   			}
   		}
   		while(x != i){
   			v.pb({x + 1, x});
   			v.pb({x, x + 1});
   			v.pb({x + 1, x});
   			swap(a[x], a[x + 1]);
   			x++;
   		}
   	}
   	cout << v.size() << "\n";
   	for(int i = 1; i <= v.size(); i++){
   		cout << v[i].F << " " << v[i].S << '\n';
   	}
}

Compilation message

xorsort.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main() {
      | ^~~~
xorsort.cpp: In function 'int main()':
xorsort.cpp:43:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i = 1; i <= v.size(); i++){
      |                    ~~^~~~~~~~~~~
xorsort.cpp:27:10: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |      int x;
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Integer 0 violates the range [1, 5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Integer 0 violates the range [1, 5]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Integer 0 violates the range [1, 5]
2 Halted 0 ms 0 KB -