답안 #493851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493851 2021-12-13T07:40:43 Z ahmeteren Garage (IOI09_garage) C++17
0 / 100
37 ms 65540 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N = 1e5 + 5;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	ll n, m;
	cin >> n >> m;

	vector<ll> c(n + 1), w(m + 1);

	for(int i = 1; i <= n; i++)
		cin >> c[i];
	for(int i = 1; i <= m; i++)
		cin >> w[i];

	ll cevap = 0;
	map<ll, ll> mp;
	set<ll> st;
	queue<ll> q;

	for(int i = 1; i <= n; i++)
		st.insert(i);

	for(int i = 0; i < 2 * m; i++)
	{
		int x;
		cin >> x;

		if(x > 0)
		{
			if(st.size())
			{
				ll a = *st.begin();
				cevap += w[x] * c[a];
				mp[x] = a;
				st.erase(st.begin());
			}
			else
			{
				q.push(x);
			}
		}
		else
		{
			x = -x;
			st.insert(mp[x]);
			if(q.size())
			{
				ll a = q.front(), b = *st.begin();
				q.pop();

				mp[a] = b;
				cevap += w[a] * c[b];
				st.erase(st.begin());
			}
		}
	}

	cout << cevap << '\n';
	return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:13:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   freopen("in.txt", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
garage.cpp:14:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   freopen("out.txt", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 65536 KB Execution killed with signal 9
2 Runtime error 29 ms 65540 KB Execution killed with signal 9
3 Runtime error 37 ms 65540 KB Execution killed with signal 9
4 Runtime error 33 ms 65540 KB Execution killed with signal 9
5 Runtime error 29 ms 65540 KB Execution killed with signal 9
6 Runtime error 31 ms 65536 KB Execution killed with signal 9
7 Runtime error 32 ms 65540 KB Execution killed with signal 9
8 Runtime error 31 ms 65540 KB Execution killed with signal 9
9 Runtime error 32 ms 65540 KB Execution killed with signal 9
10 Runtime error 31 ms 65536 KB Execution killed with signal 9
11 Runtime error 35 ms 65540 KB Execution killed with signal 9
12 Runtime error 31 ms 65540 KB Execution killed with signal 9
13 Runtime error 32 ms 65540 KB Execution killed with signal 9
14 Runtime error 30 ms 65540 KB Execution killed with signal 9
15 Runtime error 31 ms 65536 KB Execution killed with signal 9
16 Runtime error 32 ms 65536 KB Execution killed with signal 9
17 Runtime error 35 ms 65540 KB Execution killed with signal 9
18 Runtime error 31 ms 65540 KB Execution killed with signal 9
19 Runtime error 31 ms 65540 KB Execution killed with signal 9
20 Runtime error 28 ms 65536 KB Execution killed with signal 9