/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 3ms 540.0 KiB
#4 Accepted 16ms 972.0 KiB
#5 Accepted 134ms 4.66 MiB
#6 Accepted 722ms 18.637 MiB
#7 Accepted 653ms 10.633 MiB
#8 Accepted 645ms 10.59 MiB
#9 Accepted 655ms 10.492 MiB
#10 Accepted 663ms 10.637 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;
    int 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-05 13:38:06
Judged At
2024-12-09 09:00:28
Judged By
Score
100
Total Time
722ms
Peak Memory
18.637 MiB