結果

問題 No.482 あなたの名は
ユーザー kichirb3kichirb3
提出日時 2018-03-28 21:48:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 83,016 KB
実行使用メモリ 13,420 KB
最終ジャッジ日時 2023-09-07 19:31:38
合計ジャッジ時間 3,397 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 59 ms
13,196 KB
testcase_16 AC 58 ms
13,356 KB
testcase_17 AC 58 ms
13,196 KB
testcase_18 AC 58 ms
13,320 KB
testcase_19 AC 58 ms
13,352 KB
testcase_20 AC 63 ms
13,232 KB
testcase_21 AC 61 ms
13,320 KB
testcase_22 AC 59 ms
13,208 KB
testcase_23 AC 62 ms
13,284 KB
testcase_24 AC 63 ms
13,324 KB
testcase_25 AC 63 ms
13,088 KB
testcase_26 AC 61 ms
13,196 KB
testcase_27 AC 63 ms
13,088 KB
testcase_28 AC 61 ms
13,208 KB
testcase_29 AC 46 ms
13,420 KB
testcase_30 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.482 あなたの名は
// https://yukicoder.me/problems/no/482
//

#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;

string solve(int N, long long  K, vector<int> &D);

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int N;
    long long K;
    cin >> N >> K;
    vector<int> D(N+1);
    for (int i = 1; i <= N; ++i)
        cin >> D[i];
    // D[0] = 0;

    string ans = solve(N, K, D);
    cout << ans << endl;
}

string solve(int N, long long K, vector<int> &D) {
    unordered_map<int, int> num2pos;
    for (int i = 1; i <= N; ++i)
        num2pos[D[i]] = i;

    for (int i = 1; i <= N; ++i) {
        if (D[i] != i) {
            --K;
            int target_pos = num2pos[i];
            num2pos[D[i]] = target_pos;
            // num2pos[i] = i;
            // int t = D[target_pos];
            D[target_pos] = D[i];
            // D[i] = t;
        }
    }

    string ans = "NO";
    if (K >= 0 && K % 2 == 0)
        ans = "YES";
    return ans;
}
0