結果

問題 No.482 あなたの名は
ユーザー くれちー
提出日時 2017-02-11 01:29:48
言語 C90
(gcc 12.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 777 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 23,168 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-12-29 20:32:51
合計ジャッジ時間 35,608 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 TLE * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:18:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |     scanf("%lld %lld", &n, &k);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:21:15: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |     rep(i, n) scanf("%d", &d[i]);
      |               ^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i, n) for (i = 0; i < n; i++)
#define rrep(i, n) for (i = n; i >= 0; i--)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int main() {
    long long n, k;
    scanf("%lld %lld", &n, &k);

    int d[200000], i, j;
    rep(i, n) scanf("%d", &d[i]);

    int ans = 0;
    rep(i, n) {
        if (d[i] != i + 1) {
            int idx;
            for (j = i; j < n; j++) {
                if (d[j] == i + 1) { idx = j; break; }
            }
            swap(&d[i], &d[idx]);
            ans++;
        }
    }

    if (k < ans || (k - ans) % 2) puts("NO");
    else puts("YES");
    return 0;
}
0