結果
| 問題 |
No.1061 素敵な数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-23 01:15:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 1,865 bytes |
| コンパイル時間 | 2,510 ms |
| コンパイル使用メモリ | 200,948 KB |
| 最終ジャッジ日時 | 2025-01-10 15:10:53 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<int> solveB(int);
vector<int> solveA(int N){
if(N == 1) return {0, 0, 0};
if(N == 5) return {0, 1, 2, 3, 0, 4, 1, 2, 0, 3, 1, 4, 3, 4, 2};
vector<int> res;
int mx = N-1, mn = N/2;
if(N%2){
for(int i=mx; i>=mn; i--) for(int t=0; t<2; t++) res.push_back(i);
for(int i=mx; i>=mn; i--) res.push_back(i);
for(int a : solveA(N/2)) res.push_back(a);
}else{
for(int i=mn; i<=mx; i++) res.push_back(i);
res.push_back(mx);
for(int i=mn; i<mx; i++) for(int t=0; t<2; t++) res.push_back(i);
auto B = solveB(N/2);
res.push_back(B[0]);
res.push_back(mx);
B.erase(B.begin());
for(int a : B) res.push_back(a);
}
return res;
}
vector<int> solveB(int N){
if(N == 3) return {0, 1, 2, 0, 1, 2, 2, 0, 1};
if(N == 4) return {0, 1, 2, 0, 3, 1, 2, 0, 2, 3, 1, 3};
vector<int> res;
int mx = N-1, mn = N/2;
if(N%2){
res = solveB(N/2);
for(int i=mx; i>=mn; i--) for(int t=0; t<2; t++) res.push_back(i);
for(int i=mx; i>=mn; i--) res.push_back(i);
}else{
res.push_back(mx);
for(int i=mx-1; i>=mn; i--) for(int t=0; t<2; t++) res.push_back(i);
res.push_back(mx);
for(int i=mx; i>=mn; i--) res.push_back(i);
for(int a : solveA(N/2)) res.push_back(a);
}
return res;
}
int main(){
int N;
cin >> N;
if(N == 2){
cout << -1 << endl;
return 0;
}
auto ans = solveA(N);
int sz = ans.size();
for(int i=0; i<sz; i++) cout << ans[i] << " \n"[i==sz-1];
vector<vector<int>> pos(N);
for(int i=0; i<sz; i++) pos[ans[i]].push_back(i);
for(int i=0; i<N; i++){
assert(pos[i].size() == 3);
assert(abs(pos[i][0] + pos[i][2] - 2*pos[i][1]) == i);
}
return 0;
}