結果

問題 No.482 あなたの名は
ユーザー 梧桐
提出日時 2025-09-21 19:37:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 526 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 68,004 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-21 19:37:05
合計ジャッジ時間 2,957 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |     scanf("%d%lld", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>

using namespace std;

typedef long long LL;

int n, cnt;
LL k;

int main() {
    scanf("%d%lld", &n, &k);
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        if (x != i) ++cnt;
    }

    if (cnt == 0) {
        puts(k % 2 == 0 && k >= 2 ? "YES" : "NO");
    } else if (cnt == 2) {
        puts(k % 2 == 1 ? "YES" : "NO");
    } else if (cnt == 3) {
        puts(k % 2 == 0 && k >= 2 ? "YES" : "NO");
    } else {
        puts(k >= (cnt + 1) / 2 ? "YES" : "NO");
    }

    return 0;
}
0