結果
問題 | No.482 あなたの名は |
ユーザー |
|
提出日時 | 2017-02-10 22:34:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 72 ms / 2,000 ms |
コード長 | 456 bytes |
コンパイル時間 | 833 ms |
コンパイル使用メモリ | 68,992 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 19:13:23 |
合計ジャッジ時間 | 3,192 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <iostream> #include <vector> using namespace std; int main() { int n; long long K; cin >> n >> K; vector<int> D(n); vector<int> pos(n); for (int i = 0; i < n; i++) { cin >> D[i]; D[i]--; pos[D[i]] = i; } int ans = 0; for (int i = 0; i < n; i++) { if (D[i] != i) { int j = pos[i]; swap(D[i], D[j]); pos[D[i]] = i; pos[D[j]] = j; ans++; } } cout << (ans <= K && (K - ans) % 2 == 0 ? "YES" : "NO") << endl; }