結果

問題 No.3017 交互浴
コンテスト
ユーザー anchuyu
提出日時 2026-01-04 11:59:18
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 610 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,063 ms
コンパイル使用メモリ 338,576 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2026-01-04 11:59:52
合計ジャッジ時間 33,220 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main () {
  int n;
  cin >> n;
  stack<int> state;
  state.push(1e9 + 10);
  int height = 0;
  for(int i = 0; i < n; i++){
    int h;
    cin >> h;
    while(true){
      int last = state.top();
      if(last > h) break;
      state.pop();
      if(state.size() % 2 == 0){
        height += last;
      } else {
        height -= last;
      }
    }
    if((state.size() - i) % 2 == 1){
      if(i % 2 == 0){
        state.push(h);
        height += h;
      } else {
        state.push(h);
        height -= h;
      }
    }
    cout << height << endl;
  }
}
0