이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define nL '\n'
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
bool isWrong(int a, int b, int s) {
if (s == 1)
return a >= b;
return b >= a;
}
int main() {
#ifdef LOCAL
freopen("io/input.txt", "r", stdin);
freopen("io/output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int n, s;
cin >> n >> s;
vi a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vpii res;
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (isWrong(a[j], a[j+1], s)) {
res.pb({j+1, j});
a[j+1] = a[j]^a[j+1];
res.pb({j, j+1});
a[j] = a[j]^a[j+1];
res.pb({j+1, j});
a[j+1] = a[j]^a[j+1];
}
}
}
cout << res.size() << nL;
for (int i = 0; i < res.size(); i++)
cout << res[i].first+1 << " " << res[i].second+1 << nL;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
xorsort.cpp: In function 'int main()':
xorsort.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 0; i < res.size(); i++)
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |