結果

問題 No.482 あなたの名は
ユーザー DameningenDameningen
提出日時 2017-03-21 00:20:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,160 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 63,268 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 13:34:42
合計ジャッジ時間 21,096 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 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 AC 1,079 ms
4,376 KB
testcase_16 AC 1,092 ms
4,380 KB
testcase_17 AC 1,087 ms
4,376 KB
testcase_18 AC 1,085 ms
4,376 KB
testcase_19 AC 1,093 ms
4,380 KB
testcase_20 AC 1,080 ms
4,376 KB
testcase_21 AC 1,087 ms
4,380 KB
testcase_22 AC 1,095 ms
4,376 KB
testcase_23 AC 1,084 ms
4,376 KB
testcase_24 AC 1,089 ms
4,380 KB
testcase_25 AC 1,099 ms
4,376 KB
testcase_26 AC 1,086 ms
4,376 KB
testcase_27 AC 1,101 ms
4,376 KB
testcase_28 AC 1,088 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* 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