답안 #464892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464892 2021-08-14T11:42:58 Z bigo Xor Sort (eJOI20_xorsort) C++14
0 / 100
1000 ms 204 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll, ll> pii;
int main() {
	int s, n;
	cin >> n >> s;
	vector<ll>vec(n);
	for (int i = 0; i < n; i++)
		cin >> vec[i];
	vector<pii>vec1;
	vec1.push_back({ 0, 1 });
	for (int i = 1; i < n - 1; i++) {
		vec1.push_back({ i,i - 1 });
		vec1.push_back({ i,i + 1 });
	}
	vec1.push_back({ n - 1,n - 2 });
	bool fl = true;
	for (int i = 0; i < n-1; i++) {
		if (vec[i] >= vec[i + 1]) {
			fl = false;
			break;
		}
	}
	if (!fl) {
		int pla;
		while (next_permutation(vec1.begin(), vec1.end())) {
			vector<ll>tmp = vec;
			bool fl2=false;
			for (int i = 0; i < vec1.size(); i++) {
				tmp[vec1[i].first] = (tmp[vec1[i].first] ^ tmp[vec1[i].second]);
				bool fl1 = true;
				for (int j = 0; j < n - 1; j++) {
					if (tmp[j] >= tmp[j + 1]) {
						fl1 = false;
						break;
					}
				}
				if (fl1) {
					pla = i;
					fl2 = true;
					break;
				}
			}
			if (fl2)
				break;
		}
		cout << pla + 1 << endl;
		for (int i = 0; i <= pla; i++)
			cout << vec1[i].first + 1 << " " << vec1[i].second + 1 << endl;
	}
	else
		cout << 0;
}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |    for (int i = 0; i < vec1.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
xorsort.cpp:49:21: warning: 'pla' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |   for (int i = 0; i <= pla; i++)
      |                   ~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Execution timed out 1093 ms 204 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Execution timed out 1093 ms 204 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Execution timed out 1086 ms 204 KB Time limit exceeded
3 Halted 0 ms 0 KB -