結果

問題 No.482 あなたの名は
ユーザー rapurasurapurasu
提出日時 2017-03-10 15:16:24
言語 C++11
(gcc 13.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 820 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 166,484 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-06-24 07:50:31
合計ジャッジ時間 7,233 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 2
other AC * 1 RE * 11 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int swap(int*, int*)’:
main.cpp:13:1: warning: no return statement in function returning non-void [-Wreturn-type]
   13 | }
      | ^

ソースコード

diff #

 #include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
LL N,K;
int A[300000];
map<int ,int>m;
int swap(int *a,int *b){
    int temp=*a;
    *a=*b;
    *b=temp;
}
int main(){
    cin>>N>>K;
    REP(i,N){
        cin>>A[i];
        m[A[i]]=i;
    }
    REP(i,N){
        if(A[i]!=i+1){
           int b=m[i+1];
           swap(&A[i],&A[b]);
           m[A[i]]=i;
           m[A[b]]=b;
           //cout<<i+1<<" "<<b<<" "<<m[A[i]]<<" "<<m[A[b]]<<endl;
           K--;
        }
    }
    /*
    REP(i,N){
        cout<<A[i]<<endl;
    }
    cout<<K<<endl;
    */
    if(K<0){
          cout<<"NO"<<endl;
    }else{
       if(K%2==0){
          cout<<"YES"<<endl;
       }else{
          cout<<"NO"<<endl;
       }
    }
    return 0;
}
0