結果

問題 No.397 NO MORE KADOMATSU
ユーザー Mcpu3Mcpu3
提出日時 2018-09-19 16:16:19
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 828 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 29,008 KB
実行使用メモリ 24,300 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 01:55:13
合計ジャッジ時間 2,172 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,316 KB
testcase_01 AC 24 ms
24,252 KB
testcase_02 AC 23 ms
24,300 KB
testcase_03 AC 22 ms
23,448 KB
testcase_04 AC 23 ms
23,640 KB
testcase_05 AC 24 ms
23,556 KB
testcase_06 AC 25 ms
23,664 KB
testcase_07 AC 27 ms
24,156 KB
testcase_08 AC 24 ms
23,448 KB
testcase_09 AC 22 ms
23,448 KB
testcase_10 AC 40 ms
23,928 KB
testcase_11 AC 22 ms
24,264 KB
testcase_12 AC 29 ms
24,240 KB
testcase_13 AC 32 ms
23,532 KB
testcase_14 AC 32 ms
23,364 KB
testcase_15 AC 32 ms
24,156 KB
testcase_16 AC 22 ms
23,316 KB
testcase_17 AC 23 ms
23,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int b1(int n,int *a)
{
    int s=0,t,i,j;
    for(i=0;i<n-1;++i){
        for(j=n-1;j>i;--j){
            if(a[j-1]>a[j]){
                t=a[j-1];
                a[j-1]=a[j];
                a[j]=t;
                ++s;
            }
        }
    }
    return s;
}

void b2(int n,int *a)
{
    int t,i,j;
    for(i=0;i<n-1;++i){
        for(j=n-1;j>i;--j){
            if(a[j-1]>a[j]){
                t=a[j-1];
                a[j-1]=a[j];
                a[j]=t;
                printf("%d %d\n",j-1,j);
            }
        }
    }
}

int main(void)
{
    int n,a[2][100],i;
    scanf("%d",&n);
    for(i=0;i<n;++i){
        scanf("%d",&a[0][i]);
        a[1][i]=a[0][i];
    }
    printf("%d\n",b1(n,a[0]));
    b2(n,a[1]);
    fflush(0);
    return 0;
}
0