結果

問題 No.365 ジェンガソート
ユーザー nahcnuj
提出日時 2016-04-29 23:22:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 388 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 59,832 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-04 18:57:31
合計ジャッジ時間 2,265 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26 WA * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:9: warning: ‘maxi’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |         if (maxi == N-1) {
      |         ^~

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N, max = 0, maxi;
	vector<int> a;
	
	cin >> N;
	for (int i = 0, x; i < N; ++i) {
		cin >> x;
		a.push_back(x);
		
		if (max < x) max = x, maxi = i;
	}
	
	int res = N - 1;
	if (maxi == N-1) {
		for (int i = N-2; i >= 0; --i) {
			if (a[i] == max - 1) --max, --res;
		}
	}
	
	cout << res << endl;
	
	return 0;
}
0