結果

問題 No.326 あみだますたー
ユーザー niyarinniyarin
提出日時 2016-06-28 18:12:01
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,392 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 21,888 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 04:34:31
合計ジャッジ時間 4,093 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 0 ms
6,944 KB
testcase_06 WA -
testcase_07 AC 0 ms
6,944 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 WA -
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:44:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |     scanf("%d",&N);
      |     ^~~~~~~~~~~~~~
main.c:45:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |     scanf("%d",&K);
      |     ^~~~~~~~~~~~~~
main.c:49:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |         int a,b;scanf("%d %d",&a,&b);
      |                 ^~~~~~~~~~~~~~~~~~~~
main.c:57:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   57 |         scanf("%d",&aa);
      |         ^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>

int N,K;
int amida[101];
int a[101];

int ans[6000];
int anss;

void nyrn(){
    anss = 0;
    int i,j;
    int gpos[101];
    for (i=0;i<N;i++)gpos[a[i]] = i;
    while (1){
        int flag = 1;
        for (i=0;i<N;i++){
            if (a[i] != amida[i]){
                flag = 0;
                int tpos = gpos[amida[i]];
                int tmp = amida[i];
                //printf("swap %d %d\n",amida[i],amida[tpos]);
                amida[i] =  amida[tpos];
                amida[tpos] = tmp;
                int l,r;
                if (i>tpos){l = tpos;r=i;}else{l=i;r=tpos;}
                for (j=l;j<r;j++){
                    ans[anss] = j;
                    anss++;
                }
                for (j=r;j>l;j--){
                    ans[anss] = j;
                    anss++;
                }
                
            }
        }
        if (flag)break;
    }
}


int main(void){
    scanf("%d",&N);
    scanf("%d",&K);
    int i;
    for (i=0;i<N;i++)amida[i] = i;
    for (i=0;i<K;i++){
        int a,b;scanf("%d %d",&a,&b);
        a--;b--;
        int tmp = amida[a];
        amida[a] = amida[b];
        amida[b] = tmp;
    }
    for (i=0;i<N;i++){
        int aa;
        scanf("%d",&aa);
        a[i] = aa-1;
    }
    nyrn();
    printf("%d\n",anss);
    for (i=0;i<anss;i++){
        printf("%d\n",ans[i]);
    
    }
    return 0;
}
0