답안 #151069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151069 2019-09-01T16:48:24 Z youssefbou62 Garage (IOI09_garage) C++14
100 / 100
5 ms 416 KB
#include  <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }
const int N = 1e4+5 ;
int w[N],rates[105],pos[105]; 
ll ans ; 
int main(){
	int n , m ; 
	cin >> n >> m ;
	for(int i = 1 ; i <= n ; i++ )cin >> rates[i]; 
	for(int i = 1 ; i <= m ; i++ )cin >> w[i] ;
	int ans = 0 ; 
	queue<int> q; 
	for(int t = 0 ; t < 2*m ; t ++ ){
		int c , car ; 
		cin >> c ;
		car = abs(c) ; 
		if( c > 0){
			int P = -1 ; 
			for(int i = 1 ; i <= n ; i++ ){
				if( !pos[i] ){
					P = i ; 
					break ; 
				}
			}
			if( P == -1 )q.push(c);
			else pos[P] = c,ans += (w[c]*rates[P])*1LL; 
		}else{
			for(int i = 1 ; i <= n ; i++ ){
				if( pos[i] == car ){
					pos[i] = 0 ;
					break ; 
				}
			}
			int P = -1 ;
			for(int i = 1 ; i <= n ; i++ ){
				if( !pos[i] ){
					P = i ; 
					break ; 
				}
			}
			if( !q.empty() && P != -1 ){
				pos[P]=q.front();
				ans += (w[q.front()]*rates[P])*1LL; 
				q.pop() ;  
			}
		}
	}
	cout << ans << endl; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 416 KB Output is correct
20 Correct 5 ms 376 KB Output is correct