이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v;
void sw(int i, int j) {
v.push_back({j, i});
v.push_back({i, j});
v.push_back({j, i});
}
int main () {
int n, s;
cin >> n >> s;
int a[n];
for(int i = 0;i<n;i++)cin >> a[i];
if(s==2) {
vector<pair<int,int>> op;
for(int i = 19;i>=0;i--) {
for(int j = 1;j<n;j++) {
if((a[j]&(1<<i))==0 and (a[j-1]&(1<<i))!=0) {
a[j]^=a[j-1];
op.push_back({j,j-1});
}
if((a[j-1]&(1<<i))!=0) {
if((a[j-1]^a[j])<a[j-1]) {
a[j-1]^=a[j];
op.push_back({j-1,j});
}
}
}
}
cout << op.size() << "\n";
for(auto i:op) {
cout << i.first+1 << " " << i.second+1 << "\n";
}
}
else {
for(int i = 1;i<=n;i++) {
bool check = false;
for(int j = 0;j<n-i;j++) {
if(a[j] > a[j+1]) {
sw(j+1, j+2);
swap(a[j], a[j+1]);
check = true;
}
}
if(!check)break;
}
cout<<v.size()<<endl;
for(auto [i, j]:v) {
cout<<i<<' '<<j<<endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |