Submission #752466

# Submission time Handle Problem Language Result Execution time Memory
752466 2023-06-03T04:12:22 Z wenqi Garage (IOI09_garage) C++17
100 / 100
2 ms 348 KB
// trans rights
#include <bits/extc++.h>
using namespace std;
using ll = long long;

#ifdef DEBUG
#define D(args...) fprintf(stderr, args)
#else
#define D(...)
#endif

int N, M;
int rate[105], weight[2005];
int spot[105];
int own[2005];

int main(int argc, const char *argv[])
{
	scanf(" %d %d", &N, &M);
	for (int i = 1; i <= N; i++)
		scanf(" %d", &rate[i]);
	for (int i = 1; i <= M; i++)
		scanf(" %d", &weight[i]);
	int sum = 0;
	queue<int> h;
	for (int k = 0; k < 2 * M; k++)
	{
		int x;
		scanf(" %d", &x);
		if (x > 0)
		{
			int q = -1;
			for (int i = 1; i <= N; i++)
			{
				if (spot[i] == 0)
				{
					q = i;
					break;
				}
			}
			if (q == -1)
			{
				h.push(x);
			}
			else
			{
				spot[q] = x;
				sum += weight[x] * rate[q];
				own[x] = q;
			}
		}
		else
		{
			x = -x;
			spot[own[x]] = 0;
			if (h.size())
			{
				int p = h.front();
				h.pop();
				own[p] = own[x];
				spot[own[x]] = p;
				sum += weight[p] * rate[own[p]];
			}
		}
	}
	printf("%d", sum);
	return 0;
}

Compilation message

garage.cpp: In function 'int main(int, const char**)':
garage.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf(" %d %d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
garage.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf(" %d", &rate[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~
garage.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf(" %d", &weight[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
garage.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf(" %d", &x);
      |   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 348 KB Output is correct