結果

問題 No.100 直列あみだくじ
ユーザー tottoripaper
提出日時 2015-03-16 17:16:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 381 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 22,528 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-28 23:06:30
合計ジャッジ時間 1,176 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33 WA * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d", A+i);
      |         ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <cstdio>

int N, A[51];
bool used[51];

int main(){
    scanf("%d", &N);

    for(int i=1;i<=N;i++){
        scanf("%d", A+i);
    }

    int n2 = 0;
    for(int i=1;i<=N;i++){
        if(used[i]){continue;}

        int t = 1;
        for(int j=A[i];j!=i;j=A[j]){used[j] = true; t++;}

        if(t == 2){n2++;}
    }
    if(n2 & 1){puts("No");}
    else{puts("Yes");}
}
0