結果

問題 No.1635 Let’s Sort Integers!!
ユーザー logxlogx
提出日時 2021-07-07 07:43:08
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 638 bytes
コンパイル時間 3,222 ms
コンパイル使用メモリ 111,492 KB
最終ジャッジ日時 2025-01-22 17:57:39
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 TLE * 68
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<assert.h>

//愚直での確認
//WAがなければOK
int main(){
    int ti=clock();
    int n;long long k,sum;
    std::cin >> n >> k;

    std::vector<int> ans(n);
    std::iota(ans.begin(),ans.end(),1);
    do{
        if(clock()-ti > 1.9*CLOCKS_PER_SEC){
            return 1;
        }
        sum=0;
        for(int i=0;i<n-1;i++)sum+=abs(ans[i]-ans[i+1]);
        if(sum==k)break;
    }while(std::next_permutation(ans.begin(),ans.end()));

    if(sum==k)for(int i=0;i<n;i++)std::cout << ans[i] << " \n"[i+1==n];
    else std::cout << -1 << '\n';
}
0