結果

問題 No.1061 素敵な数列
ユーザー pockynypockyny
提出日時 2020-05-23 16:10:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 77,312 KB
実行使用メモリ 5,712 KB
最終ジャッジ日時 2024-04-17 00:54:34
合計ジャッジ時間 3,987 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 10 ms
5,376 KB
testcase_20 AC 9 ms
5,376 KB
testcase_21 AC 18 ms
5,376 KB
testcase_22 AC 31 ms
5,712 KB
testcase_23 AC 24 ms
5,376 KB
testcase_24 AC 24 ms
5,376 KB
testcase_25 AC 24 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 15 ms
5,376 KB
testcase_28 AC 17 ms
5,376 KB
testcase_29 AC 23 ms
5,376 KB
testcase_30 AC 27 ms
5,376 KB
testcase_31 AC 16 ms
5,376 KB
testcase_32 AC 35 ms
5,448 KB
testcase_33 AC 6 ms
5,376 KB
testcase_34 AC 9 ms
5,376 KB
testcase_35 AC 9 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int solve(int)':
main.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
   36 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
vector<int> v;
int ans4[15] = {0,0,0,1,1,2,1,3,4,4,2,3,3,2,4};
int ans5[18] = {0,0,0,1,1,2,1,2,3,4,5,2,3,3,4,4,5,5};
int solve(int n){
    int i;
    if(n==4){
        for(i=0;i<15;i++) v.push_back(ans4[i]); 
        return -1;
    }
    if(n==5){
        for(i=0;i<18;i++) v.push_back(ans5[i]);
        return -1;
    }
    if(n&1){
        int k = n/2;
        for(i=n;i>=k + 3;i--){
            v.push_back(i); v.push_back(i);
        }
        v.push_back(k + 2); v.push_back(k); v.push_back(k + 1); v.push_back(k + 1); v.push_back(k);
        for(i=n;i>=k + 1;i--) v.push_back(i);
        v.push_back(k + 2); v.push_back(k);
        return k - 1;
    }
    if(!(n&1)){
        int k = n/2;
        for(i=n;i>=k;i--){
            v.push_back(i); v.push_back(i);
        }
        for(i=n;i>=k;i--) v.push_back(i);
        return k - 1;
    }
}

int main(){
    int n; cin >> n; n--;
    if(n==1){
        cout << -1 << endl;
        return 0;
    }
    while(n!=-1){
        n = solve(n);
    }
    for(int i=0;i<v.size();i++){
        cout << v[i] << " ";
    }
    cout << endl;
}
0