結果

問題 No.397 NO MORE KADOMATSU
ユーザー btkbtk
提出日時 2016-07-16 19:53:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 1,693 ms
コンパイル使用メモリ 173,572 KB
実行使用メモリ 24,396 KB
平均クエリ数 28.00
最終ジャッジ日時 2023-09-24 00:22:06
合計ジャッジ時間 3,424 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,568 KB
testcase_01 AC 24 ms
24,324 KB
testcase_02 AC 25 ms
24,072 KB
testcase_03 AC 25 ms
23,568 KB
testcase_04 AC 25 ms
24,300 KB
testcase_05 AC 25 ms
23,628 KB
testcase_06 AC 25 ms
23,364 KB
testcase_07 AC 25 ms
24,048 KB
testcase_08 AC 24 ms
23,364 KB
testcase_09 AC 25 ms
24,300 KB
testcase_10 AC 24 ms
23,448 KB
testcase_11 AC 24 ms
24,312 KB
testcase_12 AC 25 ms
24,252 KB
testcase_13 AC 25 ms
23,652 KB
testcase_14 AC 25 ms
23,448 KB
testcase_15 AC 25 ms
24,396 KB
testcase_16 AC 24 ms
24,060 KB
testcase_17 AC 24 ms
23,820 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=N-1;j>i;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;
}
void print(vector<P>& v){
    cout<<v.size()<<endl;
    for(auto &p:v)cout<<p.first<<" "<<p.second<<endl;
    string s;cin>>s;
}

bool checkKadomatsu(int a,int b,int c){
    return (a!=c&&((a>b&&b<c)||(a<b&&b>c)));
}
bool test(vector<P>& v,vector<int> A){
    
    for(auto &it:v){
	swap(A[it.first],A[it.second]);
    }
    int N=A.size();
    for(int i=0;i+2<N;i++){
	//cout<<A[i]<<A[i+1]<<A[i+2]<<endl;
	if(checkKadomatsu(A[i],A[i+1],A[i+2]))return false;
    }
    return true;
}
vector<P> unko(int N){
    vector<P> res;
    for(int i=0;i+5<N;i+=6)
	res.push_back(P(i+3,i+5));
    res.push_back(P(0,N-2));
    return res;
}
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())q=p;
    auto kuso=unko(N);
    if(test(kuso,A)&&kuso.size()<q.size())q=kuso;
    print(q);
    return 0;
}
0