結果

問題 No.365 ジェンガソート
ユーザー フクモトN
提出日時 2021-02-17 19:18:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 89,292 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-14 05:06:36
合計ジャッジ時間 2,643 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:34:9: warning: '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