Submission #114321

# Submission time Handle Problem Language Result Execution time Memory
114321 2019-05-31T21:30:18 Z MetB Garage (IOI09_garage) C++14
100 / 100
3 ms 512 KB
#include <iostream>
#include <cstdlib>
#include <string>
#include <set>
#include <stdio.h>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <math.h>
#include <stack>
#include <vector>
#include <string.h>
 
typedef long long ll;
 
const ll MOD = 1e9 + 7, INF = 1e18;
 
using namespace std;

ll n, k, a[1000000], m, off[1000000];

vector <ll> v;

ll u[100], s[100], w[5000], p[5000], ans;

queue <ll> waiting;

int main ()
{
	cin >> n >> m;

	for (ll i = 0; i < n; i++)
		scanf ("%lld", &s[i]);

	for (ll i = 0; i < m; i++)
		scanf ("%lld", &w[i]);

	for (ll i = 0; i < 2 * m; i++)
	{
		ll t;

		scanf ("%lld", &t);

		if (t >= 0)
		{
			t--;

			bool b = false;

			for (ll j = 0; j < n; j++)
			{
				if (!u[j])
				{
					p[t] = j;
					ans += s[j] * w[t];
					u[j] = 1;
					b = true;
					break;
				}
			}

			if (!b) waiting.push (t);
		}
		else
		{
			t = abs (t) - 1;

			off[t] = 1;

			u[p[t]] = 0;

			while (!waiting.empty () && off[waiting.front ()]) waiting.pop ();

			if (!waiting.empty ())
			{
				u[p[t]] = 1;
				p[waiting.front ()] = p[t];
				ans += s[p[t]] * w[waiting.front ()];
				waiting.pop ();
			}
		}
	}

	cout << ans;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:34:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%lld", &s[i]);
   ~~~~~~^~~~~~~~~~~~~~~
garage.cpp:37:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%lld", &w[i]);
   ~~~~~~^~~~~~~~~~~~~~~
garage.cpp:43:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%lld", &t);
   ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 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 3 ms 512 KB Output is correct
20 Correct 3 ms 384 KB Output is correct