이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, cc, s, i, k, curr, j, mx;
vector<pair<int, int> > ans;
int a[1005], b[1005];
bool hasBit;
void oper(int x, int y) {
a[x] ^= a[y];
ans.push_back(make_pair(x,y));
}
int main() {
scanf("%d%d", &n, &s);
for (i=1; i <= n; ++i) {
scanf("%d", &a[i]);
b[i] = a[i];
}
if (s == 1) {
for (i=n; i >= 1; --i) {
for (j=1; j <= min(n-1, i); ++j) {
oper(j, j+1);
}
curr = 1;
for (j=2; j <= i; ++j) {
if (b[j]>b[curr]) {
curr = j;
}
}
for (j=curr-2; j >= 1; --j) {
oper(j, j+1);
}
for (j=curr+1; j <= i; ++j) {
oper(j, j-1);
}
mx = b[curr];
for (j=curr; j < i; ++j) {
b[j] = b[j+1];
}
b[i]=mx;
}
}
else {
for (i=19; i >= 0; --i) {
hasBit = false;
for (j=1; j <= n; ++j) {
if ((a[j]>>i)&1) {
hasBit = true;
}
}
if (hasBit) {
for (j=2; j <= n; ++j) {
if (!((a[j]>>i)&1)) {
oper(j, j-1);
}
}
for (j=1; j < n; ++j) {
if ((a[j]>>i)&1) {
oper(j, j+1);
}
}
--n;
}
}
}
printf("%d\n", (int)ans.size());
for (i=0; i < (int)ans.size(); ++i) {
printf("%d %d\n", ans[i].first, ans[i].second);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
xorsort.cpp: In function 'int main()':
xorsort.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d%d", &n, &s);
| ~~~~~^~~~~~~~~~~~~~~~
xorsort.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &a[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... |