# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
567634 | 2022-05-23T21:26:35 Z | losmi247 | Garage (IOI09_garage) | C++14 | 2 ms | 356 KB |
#include<iostream> #include<queue> #define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0); using namespace std; int n, m; bool P[102]; int pos[2002], cont; int R[102], W[2002]; int car; queue<int> Q; int firstP(){ for( int i = 1; i <= n; i++ ) if( !P[i] ) return i; } int main(){ optimizar_io cin >> n >> m; for( int i = 1; i <= n; i++ ) cin >> R[i]; for( int i = 1; i <= m; i++ ) cin >> W[i]; cont = n; int ans = 0; for( int i = 1; i <= 2 * m; i++ ){ cin >> car; if( car > 0 ){ if( cont ){ int f = firstP(); cont--; P[f] = true; ans += R[f] * W[car]; pos[car] = f; } else { Q.push( car ); } } else { car *= -1; int f = pos[car]; P[f] = false; cont++; if( !Q.empty() ){ car = Q.front(); Q.pop(); P[f] = true; cont--; pos[car] = f; ans += R[f] * W[car]; } } } cout << ans << "\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 328 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 316 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 324 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 2 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 356 KB | Output is correct |