結果

問題 No.411 昇順昇順ソート
コンテスト
ユーザー himueu
提出日時 2026-10-18 22:15:26
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 566 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,963 ms
コンパイル使用メモリ 182,964 KB
実行使用メモリ 9,860 KB
最終ジャッジ日時 2026-10-18 22:15:36
合計ジャッジ時間 10,072 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>

int main() {
    using namespace std;
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    iota(a.begin(), a.end(), 1);
    swap(a[0], a[k - 1]);
    sort(a.begin() + 1, a.end());
    int ans = 0;
    do {
        if (a[0] != k) { break; }
        int d = 0;
        for (int i = 0; i < n - 1; i++) {
            if (a[i] > a[i + 1]) { d++; }
        }
        if (d == 1) { ans++; }
    } while (next_permutation(a.begin(), a.end()));
    cout << ans << endl;
}
0