結果

問題 No.482 あなたの名は
ユーザー ferinferin
提出日時 2017-02-11 00:48:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,019 bytes
コンパイル時間 2,456 ms
コンパイル使用メモリ 144,224 KB
実行使用メモリ 8,764 KB
最終ジャッジ日時 2023-08-28 12:36:38
合計ジャッジ時間 8,000 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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