結果

問題 No.482 あなたの名は
ユーザー lumc_
提出日時 2017-02-15 01:11:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 634 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 53,848 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 22:49:33
合計ジャッジ時間 2,326 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |   scanf("%d%lld",&N,&K);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     scanf("%d", &d);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;
const int _N = 2e5+8;

int N;
ll K;
int D[_N];
bool p[_N]={false};
int main(void){
  scanf("%d%lld",&N,&K);
  for(int i=0;i<N;i++){
    int d;
    scanf("%d", &d);
    d--;
    D[i]=d;
  }
  ll sum = 0;
  int cnt=0,sumd=0;
  for(int i=0;i<N;i++){
    int next=0;
    while(next<N){
      if(D[next]==next || p[next]){
        cnt++;
        next = cnt;
      }else{
        p[next] = true;
        next = D[next];
        sumd++;
        if(p[next]){
          sumd--;sum+=sumd;sumd=0;
        }
      }
    }
  }
  printf("%s",(K-sum) % 2 ? "NO" : "YES");
  return 0;
}
0