結果

問題 No.397 NO MORE KADOMATSU
ユーザー Yut176Yut176
提出日時 2016-07-15 23:36:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 1,467 ms
コンパイル使用メモリ 67,904 KB
実行使用メモリ 24,372 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 00:17:45
合計ジャッジ時間 2,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,880 KB
testcase_01 AC 25 ms
23,952 KB
testcase_02 AC 26 ms
24,240 KB
testcase_03 AC 27 ms
23,664 KB
testcase_04 AC 26 ms
23,688 KB
testcase_05 AC 27 ms
23,580 KB
testcase_06 AC 29 ms
23,700 KB
testcase_07 AC 30 ms
23,376 KB
testcase_08 AC 26 ms
23,988 KB
testcase_09 AC 26 ms
24,360 KB
testcase_10 AC 48 ms
23,364 KB
testcase_11 AC 26 ms
24,048 KB
testcase_12 AC 34 ms
23,580 KB
testcase_13 AC 37 ms
24,276 KB
testcase_14 AC 39 ms
24,372 KB
testcase_15 AC 37 ms
23,604 KB
testcase_16 AC 25 ms
23,544 KB
testcase_17 AC 26 ms
23,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){

	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}

	b = a;

	// sort(b.begin(),b.end());
	int temp;
	int cnt=0;
	for (int i = 0; i < n - 1; i++) {
        for (int j = n - 1; j > i; j--) {
            if (a[j - 1] > a[j]) {
                temp = a[j];
                a[j] = a[j - 1];
                a[j - 1]= temp;
                cnt++;
                // cout << j << " " << j-1 << endl;
            }
        }	
    }
    cout << cnt << endl;
	for (int i = 0; i < n - 1; i++) {
        for (int j = n - 1; j > i; j--) {
            if (b[j - 1] > b[j]) {
                temp = b[j];
                b[j] = b[j - 1];
                b[j - 1]= temp;
                // cnt++;
                cout << j << " " << j-1 << endl;
            }
        }	
    }

    int d;
    cin >> d;

	
	return 0;
}
0