Submission #134728

# Submission time Handle Problem Language Result Execution time Memory
134728 2019-07-23T08:03:40 Z Dilshod_Imomov Garage (IOI09_garage) C++17
100 / 100
4 ms 424 KB
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
# define pb push_back
# define pf push_front
# define For(i, a, b) for( int i = a; i < b; i++ )
# define in insert
# define all(a) a.begin(),a.end()
# define pi pair < int, int >
# define DEBUG
# define readfile(file) freopen ( (file + ".in").c_str(), "r", stdin)
# define writefile(file) freopen ( (file + ".out").c_str(), "w", stdout)
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
# define LARGE (1e7)

using namespace std;
void Set_File( string file ){readfile(file);writefile(file);}

int n, m;
queue < int > line;
int car;
ll money;

int main(){
    /// Author: _Dilshod_
    speed;
    cin >> n >> m;
    vector < pi > parking(n);
    vector < pi > cars(m);
    For ( i, 0, n ){
        cin >> parking[i].fi;
    }
    For ( i, 0, m ){
        cin >> cars[i].fi;
    }
    For ( i, 0, 2 * m ){
        cin >> car;
        if ( car < 0 ){
            car *= -1;
            parking[cars[car - 1].se].se = 0;
            cars[car - 1].se = -1;
        }
        else {
            line.push(car);
        }
        For ( j, 0, n ){
            if ( !line.size() ) {
                break;
            }
            if ( !parking[j].se )
            {
                parking[j].se = 1;
                cars[line.front() - 1].se = j;
                money += parking[j].fi * cars[line.front() - 1].fi;
                line.pop();
            }
        }
    }
    cout << money;
}

Compilation message

garage.cpp: In function 'void Set_File(std::__cxx11::string)':
garage.cpp:12:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
 # define readfile(file) freopen ( (file + ".in").c_str(), "r", stdin)
                         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
garage.cpp:18:30: note: in expansion of macro 'readfile'
 void Set_File( string file ){readfile(file);writefile(file);}
                              ^~~~~~~~
garage.cpp:13:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
 # define writefile(file) freopen ( (file + ".out").c_str(), "w", stdout)
                          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
garage.cpp:18:45: note: in expansion of macro 'writefile'
 void Set_File( string file ){readfile(file);writefile(file);}
                                             ^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 424 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 380 KB Output is correct
18 Correct 4 ms 376 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct