Language: C++

/*
 * Author: FreeIdea
 * Created Time:  2011/8/22 13:58:15
 * File Name: B.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}
const int maxn = 500 + 50;

map<string, int> idx;
int n, p, cnt;

struct Pro {
    int day, time, idx;
    bool operator < (const Pro & A) const{
        if(day == A.day)    return time < A.time;
        return day < A.day;
    }
    void solve() {
        int h = time / 100;
        int m = time % 100;
        h += m / 60;
        m %= 60;
        day += h / 24;
        h %= 24;
        day %= 7;
        time = h * 100 + m;
    }
}pro[maxn];

char name[100];
int day, time;
bool must[maxn], cannot[maxn];

int hash(const string &str) {
    if(idx.count(str))  return idx[str];
    ++cnt;
    return idx[str] = cnt;
}

bool con(const Pro &p1, const Pro &p2) {
    Pro t1 = p1, t2 = p2;
    if(t2 < t1) {
        swap(t1, t2);
    }
    t1.time += 30;
    t1.solve();
    return t2 < t1;
}

int calc(int l, int r) {
    if(l > r)   return 0;
    Pro tmp;
    tmp.day = -100;
    tmp.time = -100;
    int res = 0;
    for(int i = l; i <= r; i++) {
        if(cannot[i])   continue;
        if(pro[i] < tmp) continue;
        res++;
        tmp = pro[i];
        tmp.time += 30;
        tmp.solve();
    }
    return res;
}

int main() {
    while(scanf("%d", &n) == 1 && n) {
        idx.clear();
        cnt = 0;
        for(int i = 1; i <= n; i++) {
            scanf("%s%d%d", name, &day, &time);
            pro[i].idx = hash(string(name));
            pro[i].day = day;
            pro[i].time = time;
            pro[i].solve();
        }
        scanf("%d", &p);
        memset(must, false, sizeof(must));
        memset(cannot, false, sizeof(cannot));
        for(int i = 1; i <= p; i++) {
            scanf("%s", name);
            must[hash(string(name))] = true;
        }
        stable_sort(pro + 1, pro + 1 + n);
        int last = 0;
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                if(i == j) continue;
                if(must[pro[i].idx] && must[pro[j].idx]) {
                    if(con(pro[i], pro[j])) {
                        ans = -1;
                    }
                }
            }
        }
        
        for(int i = 1; i <= n; i++) {
            if(must[pro[i].idx]) {
                for(int j = 1; j <= n; j++) {
                    if(i == j)  continue;
                    if(con(pro[i], pro[j]) || con(pro[j], pro[i])) {
                        cannot[j] = true;
                    }
                }
            }
        }
        
        if(ans != -1) {
            ans = p;
            for(int i = 1; i <= n; i++) {
                if(must[pro[i].idx]) {
                    ans += calc(last + 1, i - 1);
                    last = i;
                }
            }
            ans += calc(last + 1, n);
        }
        printf("%d\n", ans);
    }
    return 0;
}

Compiler output:
a.cc:42:10: error: 'int time' redeclared as different kind of entity
   42 | int day, time;
      |          ^~~~
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:6:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'int main()':
a.cc:84:26: error: reference to 'hash' is ambiguous
   84 |             pro[i].idx = hash(string(name));
      |                          ^~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:45:5: note:                 'int hash(const std::string&)'
   45 | int hash(const string &str) {
      |     ^~~~
a.cc:86:27: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
   86 |             pro[i].time = time;
      |                           ^~~~
      |                           |
      |                           time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
a.cc:94:18: error: reference to 'hash' is ambiguous
   94 |             must[hash(string(name))] = true;
      |                  ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:45:5: note:                 'int hash(const std::string&)'
   45 | int hash(const string &str) {
      |     ^~~~