結果

問題 No.397 NO MORE KADOMATSU
ユーザー btkbtk
提出日時 2016-07-14 21:01:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 790 bytes
コンパイル時間 1,597 ms
コンパイル使用メモリ 170,316 KB
実行使用メモリ 24,336 KB
平均クエリ数 33.44
最終ジャッジ日時 2023-09-24 00:11:41
合計ジャッジ時間 2,798 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
23,424 KB
testcase_01 AC 19 ms
23,652 KB
testcase_02 AC 23 ms
23,592 KB
testcase_03 AC 22 ms
24,048 KB
testcase_04 AC 20 ms
23,808 KB
testcase_05 AC 20 ms
23,436 KB
testcase_06 AC 21 ms
24,132 KB
testcase_07 AC 20 ms
23,448 KB
testcase_08 AC 19 ms
23,544 KB
testcase_09 AC 19 ms
23,808 KB
testcase_10 AC 20 ms
23,448 KB
testcase_11 AC 21 ms
23,652 KB
testcase_12 AC 20 ms
23,688 KB
testcase_13 AC 20 ms
23,580 KB
testcase_14 AC 19 ms
23,580 KB
testcase_15 AC 20 ms
24,336 KB
testcase_16 AC 19 ms
23,652 KB
testcase_17 AC 19 ms
23,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>







/*門松コンはいいぞ*/
/*絶対門松全問解こうな*/








using namespace std;
typedef pair<int,int> P;
vector<P> mysort(vector<int> A,int m){
    vector<P> res;
    int N=A.size();
    for(int i=0;i<N;i++)A[i]*=m;
    for(int i=0;i<N;i++){
	int bottom=A[i],id=i;
	for(int j=i+1;j<N;j++)
	    if(bottom>A[j]){
		bottom=A[j];
		id=j;
	    }
	if(id!=i)res.push_back(P(i,id));
	swap(A[i],A[id]);
    }
    return res;
    string s;cin>>s;
}
void print(vector<P>& v){
    cout<<v.size()<<endl;
    for(auto &p:v)cout<<p.first<<" "<<p.second<<endl;
}
int main(){
    int N;cin>>N;
    vector<int> A(N);
    for(auto &it:A)cin>>it;
    auto p=mysort(A,1);
    auto q=mysort(A,-1);
    if(p.size()<q.size())print(p);
    else print(q);
    return 0;
}
0