#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20;
const ll MAXN = 3e5 + 5;
vector<int> months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector<int> possible;
bool check(int day, int month, bool leap) {
if (month == 0 || day == 0 || month > 12)
return false;
int mx = months[month-1];
if (leap && month == 2)
mx++;
if (day <= mx)
return true;
return false;
}
string construct(int year) {
string ans = "";
int need_year = year;
ans = ans + char('0' + need_year % 10);
need_year/=10;
ans = ans + char('0' + need_year % 10);
need_year/=10;
ans = ans + '.';
ans = ans + char('0' + need_year % 10);
need_year/=10;
ans = ans + char('0' + need_year % 10);
need_year/=10;
ans = ans + '.';
need_year = year;
int plc0 = need_year / 1000;
int plc1 = (need_year / 100) % 10;
int plc2 = (need_year / 10) % 10;
int plc3 = need_year % 10;
ans = ans + char('0' + plc0) + char('0' + plc1) + char('0' + plc2) + char('0' + plc3) + '.';
return ans;
}
bool compat(string str1, string str2) {
int year1 = (str1[6] - '0') * 1000 + (str1[7] - '0') * 100 + (str1[8] - '0') * 10 + (str1[9] - '0');
int year2 = (str2[6] - '0') * 1000 + (str2[7] - '0') * 100 + (str2[8] - '0') * 10 + (str2[9] - '0');
if (year1 != year2)
return false;
int month1 = (str1[3] - '0') * 10 + (str1[4] - '0');
int month2 = (str2[3] - '0') * 10 + (str2[4] - '0');
if (month2 > month1)
return false;
if (month1 > month2)
return true;
int day1 = (str1[0] - '0') * 10 + (str1[1] - '0');
int day2 = (str2[0] - '0') * 10 + (str2[1] - '0');
if (day1 > day2)
return true;
return false;
}
int main() {
fast
int N;
cin >> N;
for (int i = 1; i <= 9999; i++) {
int plc0 = (i / 1000) % 10;
int plc1 = (i / 100) % 10;
int plc2 = (i / 10) % 10;
int plc3 = i % 10;
if (check(plc3 * 10 + plc2, plc1 * 10 + plc0, (i % 4) == 0))
possible.push_back(i);
}
for (int i = 0; i < N; i++) {
string s;
cin >> s;
int year = (s[6] - '0') * 1000 + (s[7] - '0') * 100 + (s[8] - '0') * 10 + (s[9] - '0');
int Q = upper_bound(possible.begin(), possible.end(), year) - possible.begin();
string ans = construct(possible[Q]);
if (Q-1 >= 0 && compat(construct(possible[Q-1]), s))
ans = construct(Q-1);
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
420 KB |
Output is correct |
10 |
Incorrect |
6 ms |
348 KB |
Output isn't correct |