| Run ID | Author | Problem | Lang | Verdict | Score | Time | Memory | Code Length | Submit Time |
|---|---|---|---|---|---|---|---|---|---|
| 119029 | 梁乃元 | 收集雨水 | C++ | Accepted | 100 | 2 MS | 348 KB | 837 | 2024-01-03 13:30:49 |
# include <bits/stdc++.h> using namespace std ; vector <int> height ; int trap ( vector <int> height ) { int left = 0 , right = height . size ( ) - 1 ; int res = 0 ; int left_max = 0 , right_max = 0; while ( left < right ) { if ( height [left] < height [right] ) { height [left] >= left_max ? ( left_max = height[left] ) : res += ( left_max - height[left] ) ; ++ left ; } else { height [right] >= right_max ? ( right_max = height [right] ) : res += ( right_max - height [right] ) ; -- right ; } } return res ; } int main ( ) { int a ; cin >> a ; for ( int i = 1 ; i <= a ; i ++ ) { int x ; cin >> x ; height . push_back ( x ) ; } cout << trap ( height) << endl ; return 0 ; }