結果
問題 |
No.482 あなたの名は
|
ユーザー |
|
提出日時 | 2020-05-04 17:42:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 689 bytes |
コンパイル時間 | 2,674 ms |
コンパイル使用メモリ | 198,524 KB |
最終ジャッジ日時 | 2025-01-10 06:24:58 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | lint k; scanf("%d%lld",&n,&k); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:29:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | rep(i,n) scanf("%d",&a[i]), a[i]--; | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; vector<vector<int>> find_cycles(const vector<int>& f){ int n=f.size(); vector<vector<int>> Res; vector<int> color(n,-1); rep(u,n) if(color[u]==-1) { int v=u; do{ color[v]=u; v=f[v]; }while(color[v]==-1); if(color[v]==u){ vector<int> C; int w=v; do{ C.emplace_back(v); v=f[v]; }while(v!=w); Res.emplace_back(C); } } return Res; } int main(){ int n; lint k; scanf("%d%lld",&n,&k); vector<int> a(n); rep(i,n) scanf("%d",&a[i]), a[i]--; lint cnt=0; for(auto C:find_cycles(a)) cnt+=C.size()-1; puts(cnt<=k&&(k-cnt)%2==0?"YES":"NO"); return 0; }