結果

問題 No.482 あなたの名は
ユーザー 梧桐
提出日時 2025-09-26 12:34:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 444 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 67,844 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-26 12:34:45
合計ジャッジ時間 3,681 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 (k == 1) puts(cnt == 2 ? "YES" : "NO");
    else if (k % 2 == 1) puts(cnt == 2 || (4 <= cnt && cnt <= k * 2) ? "YES" : "NO");
    else puts(cnt == 0 || (3 <= cnt && cnt <= k * 2) ? "YES" : "NO");

    return 0;
}
0