結果

問題 No.482 あなたの名は
ユーザー ferin
提出日時 2017-02-11 00:48:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,019 bytes
コンパイル時間 2,953 ms
コンパイル使用メモリ 157,956 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-12-29 11:39:35
合計ジャッジ時間 24,143 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 1 WA * 21 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int a[200010];

int main(void)
{
  int n, k;
  cin >> n >> k;
  REP(i, n) {
    int d;
    cin >> d;
    a[i+1] = d;
  }

  int ans = 0;
  bool used[200010];
  memset(used, false, sizeof(used));
  FOR(i, 1, n+1) {
    if(used[i]) continue;
    used[i] = true;
    int start = i, cnt = i, ret = 1;
    while(start != a[cnt]) {
      cnt = a[cnt];
      cout << cnt << endl;
      ret++;
      used[cnt] = true;
    }
    ans += (ret - 1);
  }

  //cout << ans << endl;

  if(k < ans) {
    cout << "NO" << endl;
    return 0;
  }
  if((k-ans)%2) cout << "NO" << endl;
  else cout << "YES" << endl;

  return 0;
}
0