답안 #295843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295843 2020-09-10T03:57:44 Z Hemimor Garage (IOI09_garage) C++14
100 / 100
4 ms 512 KB
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m,res=0;
vi a,b,c,d;

int main(){
	cin>>n>>m;
	a=c=vi(n);
	b=vi(m);
	d=vi(m,-1);
	for(auto &i:a) cin>>i;
	for(auto &i:b) cin>>i;
	queue<int> q;
	for(int i=0;i<2*m;i++){
		int t;
		cin>>t;
		if(t>0){
			t--;
			for(int j=0;j<n;j++) if(!c[j]){
				c[j]++;
				d[t]=j;
				res+=a[j]*b[t];
				break;
			}
			if(d[t]==-1) q.push(t);
		}
		else{
			t=-t-1;
			c[d[t]]--;
			if(!q.empty()){
				int v=q.front();
				q.pop();
				c[d[t]]++;
				d[v]=d[t];
				res+=a[d[t]]*b[v];
			}
		}
	}
	cout<<res<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 4 ms 384 KB Output is correct