結果

問題 No.482 あなたの名は
ユーザー DameningenDameningen
提出日時 2017-03-21 00:06:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,224 bytes
コンパイル時間 3,123 ms
コンパイル使用メモリ 65,052 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-18 13:29:28
合計ジャッジ時間 36,256 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int main()
{
    //人数Nと操作Kを宣言
    int N;
    long K;
    
    cin >> N >> K;
    
    //数列用の動的配列を設定
    int* const array = new int[N];                                                   //動的配列arrayを設定
    
    //arrayに数値を設定
    for (int i = 0; i < N; i++) {
        cin >> array[i];
    }
    
    
    
    
    //操作の必要最小回数を算出
    int operation = 0;
    
    for (int i = 0; i < N; i++) {
        if (array[i] == i + 1) {
            //何もしない
        } else {
            //i+1と同じ値が入ってる要素のindex
            static int _i = 0;
            
            _i = i + 1;
            
            while (array[_i] != i + 1) {
                _i++;
            }
            
            array[_i] = array[i];
            
            operation++;
        }
    }
    
    delete[] array;                                                            //動的配列arrayを解放
    
    //YESかNOかの判定
    if (operation > K) {
        cout << "NO" << endl;
    } else {
        cout << ((K % 2 != operation % 2) ? "NO" : "YES") << endl;
    }
    
    return 0;
}
0