結果
問題 | No.365 ジェンガソート |
ユーザー |
![]() |
提出日時 | 2016-04-29 22:32:23 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 919 bytes |
コンパイル時間 | 616 ms |
コンパイル使用メモリ | 76,344 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-12 01:39:07 |
合計ジャッジ時間 | 2,248 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 |
ソースコード
#include <iostream>#include <string>#include <vector>#include <sstream>#include <map>#include <set>#include <queue>#include <algorithm>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;using ll = long long;#define all(c) (c).begin(), (c).end()#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define pb(e) push_back(e)#define mp(a, b) make_pair(a, b)#define fr first#define sc secondconst ll INF = 1e9;const ll MOD = 1e9 + 7;int dx[4] = {1, 0, -1, 0};int dy[4] = {0, 1, 0, -1};int N;vector<int> a;int main() {cin >> N;a.resize(N);rep(i, N) cin >> a[i];int pos = max_element(all(a)) - a.begin();int ans = N - pos - 1;int v = a[pos];for (int i = pos - 1; i >= 0; i--) {if (v - 1 != a[i]) {ans++;} else {v = a[i];}}cout << ans << endl;return 0;}