結果
| 問題 |
No.482 あなたの名は
|
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2017-02-07 08:46:18 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 441 bytes |
| コンパイル時間 | 1,286 ms |
| コンパイル使用メモリ | 157,920 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-29 18:59:58 |
| 合計ジャッジ時間 | 3,514 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:17: warning: use of an operand of type ‘bool’ in ‘operator++’ is deprecated [-Wdeprecated]
20 | while(!v[now]++) now = D[now], sz++;
| ~~~~~^
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N, D[200000];
long long K;
cin >> N >> K;
for(int i = 0; i < N; i++) {
cin >> D[i];
--D[i];
}
bool v[200000] = {};
for(int i = 0; i < N; i++) {
if(v[i]) continue;
int sz = 0, now = i;
while(!v[now]++) now = D[now], sz++;
K -= sz - 1;
}
if(K % 2 == 0 && K >= 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
ei1333333