Submission #1297281

#TimeUsernameProblemLanguageResultExecution timeMemory
1297281the_commando_xGarage (IOI09_garage)C++20
100 / 100
2 ms580 KiB
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

using pii = pair<int, int>;
using vii = vector<pii>;
using vvii = vector<vii>;

using l = long long;
using vl = vector<l>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;

using pll = pair<l, l>;
using vll = vector<pll>;
using vvll = vector<vll>;

using d = double;
using vd = vector<d>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;

using ld = long double;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;

using vb = vector<bool>;
using vvb = vector<vb>;
using pbb = pair<bool, bool>;
using vbb = vector<pbb>;

#define ff first
#define ss second

#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (!name.empty())
    {
        (void)freopen((name + ".in").c_str(), "r", stdin);
        (void)freopen((name + ".out").c_str(), "w", stdout);
    }
}

const ld pi = 3.14159265358979323846;

const l LINF = 1e18;
const l INF = 1e9;

const l MOD = 1e9 + 7;
// const l MOD = 998244353;

const l MAXN = 1e2 + 5, MAXM = 2e3 + 5;
vi rate(MAXN), weight(MAXM), parking(MAXN, -1); // parking[i] = car_id or -1 if empty
queue<int> waiting;
l total = 0;

void solve()
{
    int N, M;
    cin >> N >> M;

    for (int i = 0; i < N; i++)
        cin >> rate[i];
    for (int i = 0; i < M; i++)
        cin >> weight[i];

    vi events(2 * M);
    for (int i = 0; i < 2 * M; i++)
        cin >> events[i];

    for (int i = 0; i < 2 * M; i++)
    {
        int car = abs(events[i]) - 1;
        if (events[i] > 0)
        { // arrival
            bool parked = false;
            for (int j = 0; j < N; j++)
            {
                if (parking[j] == -1)
                {
                    parking[j] = car;
                    parked = true;
                    break;
                }
            }
            if (!parked)
                waiting.push(car);
        }
        else
        { // departure
            int space;
            for (space = 0; space < N; space++)
                if (parking[space] == car)
                    break;

            total += (l)weight[car] * rate[space];
            parking[space] = -1;
            if (waiting.size())
            {
                int next_car = waiting.front();
                waiting.pop();
                parking[space] = next_car; // assign the exact freed space
            }
        }
    }

    cout << total;
}

int main()
{
    setIO("");

#ifndef ONLINE_JUDGE
    // setIO("filename");
#endif

    int t = 1;
    // cin >> t;
    while (t--)
        solve();

    return 0;
}

Compilation message (stderr)

garage.cpp: In function 'void setIO(std::string)':
garage.cpp:52:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         (void)freopen((name + ".in").c_str(), "r", stdin);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
garage.cpp:53:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         (void)freopen((name + ".out").c_str(), "w", stdout);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...