結果

問題 No.365 ジェンガソート
ユーザー フクモトNフクモトN
提出日時 2021-02-17 19:18:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 5,180 KB
最終ジャッジ日時 2023-10-12 05:40:41
合計ジャッジ時間 2,788 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 17 ms
4,696 KB
testcase_17 AC 21 ms
5,140 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 20 ms
4,848 KB
testcase_20 AC 7 ms
4,352 KB
testcase_21 AC 6 ms
4,352 KB
testcase_22 AC 16 ms
4,636 KB
testcase_23 AC 10 ms
4,348 KB
testcase_24 AC 15 ms
4,624 KB
testcase_25 AC 5 ms
4,348 KB
testcase_26 AC 13 ms
4,348 KB
testcase_27 AC 20 ms
5,072 KB
testcase_28 AC 12 ms
4,348 KB
testcase_29 AC 19 ms
4,780 KB
testcase_30 AC 13 ms
4,400 KB
testcase_31 AC 6 ms
4,348 KB
testcase_32 AC 6 ms
4,348 KB
testcase_33 AC 20 ms
5,068 KB
testcase_34 AC 4 ms
4,348 KB
testcase_35 AC 16 ms
4,676 KB
testcase_36 AC 21 ms
5,148 KB
testcase_37 AC 20 ms
5,180 KB
testcase_38 AC 21 ms
5,128 KB
testcase_39 AC 21 ms
5,076 KB
testcase_40 AC 21 ms
5,072 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:34:9: 警告: ‘maxnum’ may be used uninitialized [-Wmaybe-uninitialized]
   34 |     int maxnum;
      |         ^~~~~~

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <sstream>
//#include <iterator>
//#include <iomanip>

using namespace std;
using ll = unsigned long long;

typedef pair<ll, ll> P;
map<int,int> dp;
vector<int> X;
vector<int> Y;
vector<int> Z;

int main(void){
    string a;
    getline(cin, a);
    string lineF;
    getline(cin, lineF);
    vector<int> N;
    istringstream iss(lineF);
    int k;
    int mx=0;
    int num=0;
    int maxnum;
    while(iss >>k){
        N.push_back(k);
        mx=max(mx,k);
        if(mx==k){
            maxnum=num;
        }
        num++;
    }
    int ans=num-maxnum-1;
    for(int k=maxnum;k>=0;k--){
        if(N[k]==N[maxnum]-1){
            ans+=maxnum-k-1;
            maxnum = k;
        }
    }
    cout << ans+maxnum <<endl;

}
0