/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 488.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 4ms 504.0 KiB
#4 Accepted 27ms 1000.0 KiB
#5 Accepted 231ms 4.641 MiB
#6 Accepted 1345ms 18.637 MiB
#7 Accepted 1244ms 10.676 MiB
#8 Accepted 1208ms 10.539 MiB
#9 Accepted 1209ms 10.645 MiB
#10 Accepted 1198ms 10.602 MiB

Code

#include <cstdio>
#include <string>
#include <iostream>
#include <map>
#include <queue>
#include <cassert>
using namespace std;

const int total_people_limit = 5e5;
const int number_of_days_limit = 1e4;
const int number_of_priority_jobs_limit = 150;
const int number_of_age_groups_limit = 7;

map <string, int> job_priorities;
int ages[126];
struct people {
    int id;
    int age;
    string name;
    string job;
    int priority;
    people(int _id, int _age, string _name, string _job) {
        assert(0 < _id);
        assert(0 < _age && _age <= 125);
        this->id = _id;
        this->age = _age;
        this->name = _name;
        this->job = _job;
        this->priority = job_priorities[this->job] + ages[this->age];
    }
    bool operator < (const people &rhs) const {
        if (this->priority == rhs.priority) {
            return this->id > rhs.id;
        }
        return this->priority < rhs.priority;
    }
};

priority_queue <people> pq;

int main() {
    int total_people = 0;
    int number_of_days;
    int number_of_priority_jobs;
    int number_of_age_groups;
    string job, name;
    int job_priority, id, age;
    scanf("%d %d %d", &number_of_days, &number_of_priority_jobs, &number_of_age_groups);
    for (int i = 0; i < number_of_priority_jobs; i++) {
        cin >> job >> job_priority;
        assert(job_priority <= number_of_priority_jobs);
        job_priorities[job] = job_priority;
    }
    for (int i = 0; i < number_of_age_groups; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        assert(x <= y);
        assert(0 < x && y <= 125);
        assert(z <= number_of_age_groups);
        for (int j = x; j <= y; j++) {
            ages[j] = z;
        }
    }
    id = 0;
    long long vaccine_available = 0;
    for (int i = 0 ; i < number_of_days; i++) {
        int n, m;
        cin >> n >> m;
        total_people += n;
        vaccine_available += m;
        assert(n > 0);
        assert(m >= 0);
        // cerr << "day " << (i + 1) << ":\n";
        for (int j = 0; j < n; j++) {
            cin >> name >> job >> age;
            assert(0 < age && age <= 125);
            pq.push(people(++id, age, name, job));
        }
        while (vaccine_available > 0 && pq.size() > 0)
        {
            people it = pq.top();
            cout << it.name << " " << it.job << " " << it.age;
            // cerr << " " << it.priority << " " << it.id;
            cout << "\n";
            pq.pop();
            vaccine_available--;
        }
    }
    assert(total_people <= total_people_limit);
    cout << "Still unvaccinated people: " << pq.size() << "\n";
}

Information

Submit By
Type
Submission
Problem
P1148 e-Vaccine
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-17 02:24:32
Judged At
2024-12-17 12:05:14
Judged By
Score
100
Total Time
1345ms
Peak Memory
18.637 MiB