Submission #134728

#TimeUsernameProblemLanguageResultExecution timeMemory
134728Dilshod_ImomovGarage (IOI09_garage)C++17
100 / 100
4 ms424 KiB
# 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 (stderr)

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 timeMemoryGrader output
Fetching results...