結果

問題 No.482 あなたの名は
ユーザー kichirb3kichirb3
提出日時 2018-03-28 21:43:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 82,768 KB
実行使用メモリ 13,520 KB
最終ジャッジ日時 2023-09-07 19:31:31
合計ジャッジ時間 4,187 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 67 ms
13,192 KB
testcase_16 AC 70 ms
13,212 KB
testcase_17 AC 63 ms
13,408 KB
testcase_18 AC 65 ms
13,192 KB
testcase_19 AC 64 ms
13,412 KB
testcase_20 AC 69 ms
13,520 KB
testcase_21 AC 64 ms
13,272 KB
testcase_22 AC 67 ms
13,312 KB
testcase_23 AC 64 ms
13,520 KB
testcase_24 AC 66 ms
13,328 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 35 ms
13,212 KB
testcase_28 AC 35 ms
13,200 KB
testcase_29 WA -
testcase_30 AC 2 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, int K, vector<int> &D);

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

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

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

string solve(int N, int 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