結果

問題 No.397 NO MORE KADOMATSU
ユーザー ngtkanangtkana
提出日時 2020-03-21 11:58:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 1,837 ms
コンパイル使用メモリ 204,992 KB
実行使用メモリ 24,312 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 02:33:10
合計ジャッジ時間 3,902 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
23,376 KB
testcase_01 AC 21 ms
23,652 KB
testcase_02 AC 23 ms
24,060 KB
testcase_03 AC 25 ms
23,388 KB
testcase_04 AC 22 ms
24,312 KB
testcase_05 AC 22 ms
23,952 KB
testcase_06 AC 23 ms
23,352 KB
testcase_07 AC 25 ms
23,652 KB
testcase_08 AC 21 ms
23,544 KB
testcase_09 AC 20 ms
23,664 KB
testcase_10 AC 47 ms
24,288 KB
testcase_11 AC 20 ms
23,652 KB
testcase_12 AC 28 ms
24,288 KB
testcase_13 AC 30 ms
24,276 KB
testcase_14 AC 30 ms
23,520 KB
testcase_15 AC 31 ms
23,376 KB
testcase_16 AC 20 ms
23,796 KB
testcase_17 AC 20 ms
23,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    std::vector<std::pair<lint,lint>>ans;
    for(lint i=0;i<n;i++){
        for(lint j=0;j<n-1-i;j++){
            if(a.at(j)>a.at(j+1)){
                ans.emplace_back(j,j+1);
                std::swap(a.at(j),a.at(j+1));
            }
        }
    }
    std::cout<<ans.size()<<'\n';
    for(auto&&p:ans){
        std::cout<<p.first<<" "<<p.second<<std::endl;
    }
    std::cout<<std::flush;
    assert(std::is_sorted(a.begin(),a.end()));
}

0