Submission #1080808

# Submission time Handle Problem Language Result Execution time Memory
1080808 2024-08-29T14:29:42 Z Dennis_Jason Garage (IOI09_garage) C++14
100 / 100
8 ms 520 KB
#include <bits/stdc++.h>
#define NMAX 100001
#define pb push_back
#define eb emplace_back
#define MOD 100003
#define nl '\n'
#define INF  2147483647
#define LLONG_MAX 9223372036854775807
#define pii pair<int,int>
#define tpl tuple<int,int,int>
//#pragma GCC optimize("O3")
using namespace std;
ifstream fin("cerc.in");
ofstream fout("cerc.out");
/*
 *
 *
    ================DEMONSTRATION===================


    =====================END========================
 */
int n,m,ans;
set<tpl>space;
vector<int>w;
vector<int>arrived;
vector<int>depart;
signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;
    w.resize(m+1);
    arrived.resize(m+1);
    depart.resize(m+1);
    for(int i=1;i<=n;++i)
    {
        int x;
        cin>>x;
        space.insert({-1,i,x});
    }
    for(int i=1;i<=m;++i)
    {
        cin>>w[i];
    }
    queue<int>q;
    for(int i=1;i<=2*m;++i)
    {
        int x;
        cin>>x;
        if(x>0)
        {
            q.push(x);
            arrived[x]=i;
        }
        else
        {
            depart[abs(x)]=i;
        }
    }
    while(!q.empty())
    {
        auto car=q.front();
        q.pop();
        vector<std::set<tuple<int, int, int>>::iterator> aux;
        for(auto it=space.begin();it!=space.end();++it)
        {
            auto [timp,loc,pret]=*it;
            if(timp<=arrived[car])
                aux.pb(it);
        }
        for(auto x:aux)
        {
            auto [timp,loc,pret]=*x;
            space.erase(x);
            space.insert({-1,loc,pret});
        }

        auto it=space.begin();
        auto[timp,loc,pret]=*it;
        ans+=(w[car]*pret);
        space.erase(it);
        space.insert({depart[car],loc,pret});
//        cout<<car<<" "<<loc<<nl;
    }

    cout<<ans;





    return 0;
}

Compilation message

garage.cpp:8: warning: "LLONG_MAX" redefined
    8 | #define LLONG_MAX 9223372036854775807
      | 
In file included from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:195,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:34,
                 from /usr/include/c++/10/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
                 from garage.cpp:1:
/usr/include/limits.h:135: note: this is the location of the previous definition
  135 | #  define LLONG_MAX __LONG_LONG_MAX__
      | 
garage.cpp: In function 'int main()':
garage.cpp:69:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   69 |             auto [timp,loc,pret]=*it;
      |                  ^
garage.cpp:75:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   75 |             auto [timp,loc,pret]=*x;
      |                  ^
garage.cpp:81:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   81 |         auto[timp,loc,pret]=*it;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 6 ms 348 KB Output is correct
17 Correct 4 ms 348 KB Output is correct
18 Correct 5 ms 520 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 8 ms 348 KB Output is correct