結果

問題 No.482 あなたの名は
ユーザー DameningenDameningen
提出日時 2017-03-21 00:13:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,166 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 64,544 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 13:31:17
合計ジャッジ時間 20,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 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 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1,083 ms
4,376 KB
testcase_16 AC 1,096 ms
4,380 KB
testcase_17 AC 1,092 ms
4,376 KB
testcase_18 AC 1,086 ms
4,384 KB
testcase_19 AC 1,094 ms
4,376 KB
testcase_20 AC 1,085 ms
4,380 KB
testcase_21 AC 1,086 ms
4,380 KB
testcase_22 AC 1,100 ms
4,376 KB
testcase_23 AC 1,083 ms
4,380 KB
testcase_24 AC 1,090 ms
4,376 KB
testcase_25 AC 1,106 ms
4,376 KB
testcase_26 AC 1,093 ms
4,380 KB
testcase_27 AC 1,103 ms
4,380 KB
testcase_28 AC 1,089 ms
4,380 KB
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
            int _i = i + 1;
            
            while (array[_i] != i + 1) {
                _i++;
            }
            
            array[_i] = array[i];
            
            operation++;
        }
    }
    
    //YESかNOかの判定
    if (operation > K || K % 2 != operation % 2) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    
    delete[] array;                                                    //動的配列arrayを解放
    
    return 0;
}
0