結果
| 問題 | No.929 よくあるボールを移動するやつ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-03 17:13:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,412 bytes |
| 記録 | |
| コンパイル時間 | 1,533 ms |
| コンパイル使用メモリ | 171,352 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-23 20:18:32 |
| 合計ジャッジ時間 | 2,372 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 WA * 8 |
ソースコード
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
stack<pll> st;
ll ans = 0;
rep(i, N) {
ll a;
cin >> a;
if (a == 1)
continue;
if (st.empty()) {
st.push({a, i});
} else if (a == 0) {
int tar = st.top().first;
if (tar == 0) {
st.push({a, i});
} else {
st.top().first--;
ans += abs(st.top().second - i);
if (st.top().first == 0)
st.pop();
}
} else {
while (1) {
if (st.empty()) {
st.push({a, i});
break;
}
int tar = st.top().first;
if (tar != 0) {
st.push({a, i});
break;
} else {
a--;
ans += abs(st.top().second - i);
st.pop();
if (a == 0)
break;
}
}
}
}
cout << ans << endl;
}