結果

問題 No.326 あみだますたー
ユーザー niyarinniyarin
提出日時 2016-06-28 18:45:22
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,525 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 21,888 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-20 03:44:40
合計ジャッジ時間 5,051 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
13,756 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 0 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 1 ms
6,940 KB
testcase_08 WA -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:47:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |     scanf("%d",&N);
      |     ^~~~~~~~~~~~~~
main.c:48:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |     scanf("%d",&K);
      |     ^~~~~~~~~~~~~~
main.c:52:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   52 |         int a,b;scanf("%d %d",&a,&b);
      |                 ^~~~~~~~~~~~~~~~~~~~
main.c:60:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |         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]+1,amida[tpos]+1);
                amida[i] =  amida[tpos];
                amida[tpos] = tmp;
                int l,r;
                if (i>tpos){l = tpos;r=i;}else{l=i;r=tpos;}
                //printf("%d %d\n",l,r);
                for (j=l;j<r;j++){
                    ans[anss] = j;
                    //printf(">>%d\n",j);
                    anss++;
                }
                for (j=r-2;j>l-1;j--){
                    ans[anss] = j;
                    //printf("<<%d\n",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