답안 #953191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953191 2024-03-25T16:36:43 Z DearSimone Garage (IOI09_garage) C++17
100 / 100
1 ms 604 KB
#include "bits/stdc++.h"
using namespace std;
 
typedef long long int64;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif
 
 
const int MOD = 1000000007;

int indexFirstEmpty(const vector<int>& v) {

    for (int i = 0; i < v.size(); i++) {
        if (v[i] == -1)
            return i;
    }
    
    return -1;
}

int indexOfCar(const vector<int>& v, int car) {

    for (int i = 0; i < v.size(); i++) {
        if (v[i] == car) {
            return i;
        }
    }

    return -1;
}

void solve() {
    
    int spaces, cars;
    cin >> spaces >> cars;

    int ans = 0;

    vector<int> parking(spaces, -1);
    vector<int> rate_space(spaces);
    vector<int> weight_cars(cars);

    queue<int> line;

    for (int i = 0; i < spaces; i++)
        cin >> rate_space[i];
    
    for (int i = 0; i < cars; i++)
        cin >> weight_cars[i];
    

    dbg(parking);
    dbg(rate_space);
    dbg(weight_cars);

    for (int i = 0; i < 2*cars; i++) {
        int curr_car; cin >> curr_car;
        
        dbg(parking);
        if (curr_car > 0) {
            if (!line.empty()) {
                line.push(curr_car);
                continue;
            }

            int avail = indexFirstEmpty(parking);
            if (avail == -1) {
                line.push(curr_car);
                continue;
            }

            ans += rate_space[avail] * weight_cars[curr_car-1];
            parking[avail] = curr_car;
        }

        else {
            // check if any car on queue and let it in
            int new_empty = indexOfCar(parking, curr_car*-1);
            parking[new_empty] = -1;

            if (!line.empty()) {
                ans += rate_space[new_empty] * weight_cars[line.front()-1];
                parking[new_empty] = line.front();
                line.pop();
            }
        }
    }

    cout << ans << '\n';

}
 
int main() {
    ios_base::sync_with_stdio(0); 
	cin.tie(0);
 
    int T = 1;
    while(T--) {
        solve();
    }
 
	return 0;
}


Compilation message

garage.cpp: In function 'int indexFirstEmpty(const std::vector<int>&)':
garage.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
garage.cpp: In function 'int indexOfCar(const std::vector<int>&, int)':
garage.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 356 KB Output is correct
9 Correct 1 ms 356 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 360 KB Output is correct
12 Correct 0 ms 356 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct