結果
問題 | No.482 あなたの名は |
ユーザー |
![]() |
提出日時 | 2017-02-11 00:15:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 694 bytes |
コンパイル時間 | 1,606 ms |
コンパイル使用メモリ | 167,192 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-12-29 20:23:49 |
合計ジャッジ時間 | 3,243 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include<bits/stdc++.h>using namespace std;#define rep(i,a,b) for(int i=a;i<b;i++)typedef long long ll;int N; ll K;int D[201010];//-----------------------------------------------------------------int idx[201010];string sol() {rep(i, 0, N) idx[D[i]] = i;int cnt = 0;rep(i, 0, N) {if (idx[i] == i) continue;int j = i, k = idx[i];int a = D[j], b = D[k];swap(D[j], D[k]);swap(idx[a], idx[b]);cnt++;}ll d = K - cnt;if (d < 0) return "NO";if (d % 2 == 0) return "YES";return "NO";}//-----------------------------------------------------------------int main() {cin >> N >> K;rep(i, 0, N) scanf("%d", &D[i]), D[i]--;cout << sol() << endl;}