提出 #67333682
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
class Solution {
int *a;
int n;
public:
Solution(int sz) {
n = sz;
a = new int[1 << n];
}
void input() {
for (int i = 0; i < (1 << n); ++i) {
cin >> *(a + i);
}
}
vector<int> solve() {
return build(0, 1 << n);
}
void output() {
vector<int> res = solve();
for (size_t i = 0; i < res.size(); ++i) {
cout << res[i] << (i + 1 < res.size() ? ' ' : '\n');
}
}
private:
vector<int> build(int start, int len) {
if (len == 1) {
return { *(a + start) };
}
int half = len >> 1;
vector<int> L = build(start, half);
vector<int> R = build(start + half, half);
vector<int> opt1, opt2;
stack<int> st;
for (int x : L) st.push(x);
for (int x : R) st.push(x);
while (!st.empty()) {
opt1.push_back(st.top());
st.pop();
}
reverse(opt1.begin(), opt1.end());
for (int x : R) st.push(x);
for (int x : L) st.push(x);
while (!st.empty()) {
opt2.push_back(st.top());
st.pop();
}
reverse(opt2.begin(), opt2.end());
return (opt1 < opt2) ? opt1 : opt2;
}
};
int main() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
Solution *sol = new Solution(N);
sol->input();
sol->output();
delete sol;
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Reverse 2^i |
| ユーザ | Naman____17 |
| 言語 | C++ 17 (Clang 16.0.6) |
| 得点 | 450 |
| コード長 | 1619 Byte |
| 結果 | AC |
| 実行時間 | 201 ms |
| メモリ | 9568 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 450 / 450 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt |
| All | 00_sample_00.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3636 KiB |
| 01_test_00.txt | AC | 1 ms | 3500 KiB |
| 01_test_01.txt | AC | 1 ms | 3504 KiB |
| 01_test_02.txt | AC | 129 ms | 5320 KiB |
| 01_test_03.txt | AC | 11 ms | 3740 KiB |
| 01_test_04.txt | AC | 111 ms | 4800 KiB |
| 01_test_05.txt | AC | 111 ms | 4836 KiB |
| 01_test_06.txt | AC | 113 ms | 4800 KiB |
| 01_test_07.txt | AC | 114 ms | 4684 KiB |
| 01_test_08.txt | AC | 133 ms | 4924 KiB |
| 01_test_09.txt | AC | 138 ms | 5120 KiB |
| 01_test_10.txt | AC | 134 ms | 5064 KiB |
| 01_test_11.txt | AC | 152 ms | 9500 KiB |
| 01_test_12.txt | AC | 148 ms | 7036 KiB |
| 01_test_13.txt | AC | 141 ms | 5248 KiB |
| 01_test_14.txt | AC | 201 ms | 7028 KiB |
| 01_test_15.txt | AC | 133 ms | 9412 KiB |
| 01_test_16.txt | AC | 133 ms | 9440 KiB |
| 01_test_17.txt | AC | 133 ms | 9512 KiB |
| 01_test_18.txt | AC | 134 ms | 9568 KiB |
| 01_test_19.txt | AC | 137 ms | 9532 KiB |
| 01_test_20.txt | AC | 137 ms | 9468 KiB |
| 01_test_21.txt | AC | 136 ms | 9532 KiB |
| 01_test_22.txt | AC | 136 ms | 9552 KiB |
| 01_test_23.txt | AC | 137 ms | 9440 KiB |
| 01_test_24.txt | AC | 137 ms | 9300 KiB |