forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbirthdayboy.cpp
105 lines (85 loc) · 1.86 KB
/
birthdayboy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <bits/stdc++.h>
using namespace std;
struct date {
int m, d;
};
bool operator<(const date& d1, const date& d2) {
if(d1.m == d2.m) {
return d1.d < d2.d;
}
return d1.m < d2.m;
}
bool operator==(const date& d1, const date& d2) {
return (d1.m == d2.m) && (d1.d == d2.d);
}
int main() {
vector<int> days = {31,28,31,30,31,30,31,31,30,31,30,31};
set<date> all;
for(int i = 0; i < 12; i++) {
for(int j = 0; j < days[i]; j++) {
date d;
d.m = i+1;
d.d = j+1;
all.insert(d);
}
}
set<date> coworker;
int n;
cin >> n;
for(int i = 0; i < n; i++) {
string s;
cin >> s;
date d;
cin >> d.m;
cin.ignore();
cin >> d.d;
coworker.insert(d);
}
int ans = 0;
set<date> best;
// for each start point
for(auto i : all) {
auto it = all.find(i);
if(coworker.count(i)) {
continue;
}
int dayswithout = 0;
while(true) {
it = next(it);
if(it == all.end()) {
it = all.begin();
}
date d = *(it);
if(coworker.count(d)) {
break;
}
// process here
dayswithout++;
if(dayswithout > ans) {
best.clear();
}
if(dayswithout >= ans) {
ans = dayswithout;
best.insert(d);
}
if(d == i) {
break;
}
}
}
auto d1 = best.lower_bound({10,28});
auto d2 = best.begin();
date d;
if(d1 != best.end()) {
d = *d1;
}
else {
d = *d2;
}
if(d.m < 10) cout << "0";
cout << d.m;
cout << "-";
if(d.d < 10) cout << "0";
cout << d.d;
cout << endl;
}