| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 775351 | Antonn_114 | Xor Sort (eJOI20_xorsort) | C++14 | 6 ms | 972 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
// Write down the limits of the problem here
int main() {
// Try to avoid cin, cout :)
int tc = 1; // scanf("%d", &tc);
while(tc--) {
/// Your solution here
int n, s;
scanf("%d%d", &n, &s);
vector<int> a(n);
vector<pair<int, int>> actions;
for (auto&i : a) scanf("%d", &i);
if (s == 1){
vector<int> c = a;
map<int, int> bbb;
for (int i = 0; i < n; i++){
bbb[a[i]] = i;
}
for (int i = 0; i < n - 1; i++){
actions.push_back({i, i + 1});
c[i] ^= c[i + 1];
}
int lol = 0;
for (auto it = bbb.rbegin(); it != bbb.rend(); it++){
for (int j = it->second; j < n - 1 - lol; j++){
actions.push_back({j + 1, j});
c[j + 1] ^= c[j];
bbb[a[j + 1]]--;
a[j] = a[j + 1];
}
for (int j = max(it->second - 1, 0); j < n - lol - 1; j++){
actions.push_back({j, j + 1});
c[j] ^= c[j + 1];
}
lol++;
}
printf("%d\n", int(actions.size()));
for (auto &i : actions){
printf("%d %d\n", i.first + 1, i.second + 1);
}
}
else if (s == 2){
vector<int> b = a;
int cnttt = 0;
for (int i = 19; i >= 0; i--){
vector<int> ids;
for (int j = 0; j < n - cnttt; j++){
if ((b[j] >> i) & 1){
ids.push_back(j);
}
}
if (!ids.empty()){
for (auto &j : ids){
int ptr = j;
while(ptr > 0 && (((b[ptr - 1] >> i) & 1) ^ 1)){
actions.push_back({ptr - 1, ptr});
b[ptr - 1] ^= b[ptr];
ptr--;
}
}
int ptr = *ids.rbegin();
while(ptr < n - 1 && (((b[ptr + 1] >> i) & 1) ^ 1)){
b[ptr + 1] ^= b[ptr];
actions.push_back({ptr + 1, ptr});
ptr++;
}
for (int j = 0; j < n - 1 - cnttt; j++){
actions.push_back({j, j + 1});
b[j] ^= b[j + 1];
}
cnttt++;
}
}
printf("%d\n", int(actions.size()));
for (auto& i : actions){
printf("%d %d\n", i.first + 1 ,i.second + 1);
a[i.first] ^= a[i.second];
}
}
}
return 0;
}
/*
* Ermm don't underestimate Div2A, pls...
*
* IMPORTANT:: If there isn't a clear-cut approach for your program, DO NOT CODE YET!
*
* Analyze the time complexity and space complexity even if it *seems* efficient
*
* Write down some notes for more complicated problems
*
* Also, please, CP isn't supposed to be complicated
*
**/
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
