#include <bits/stdc++.h>
#pragma optimize "DostSeferoğlu"
#pragma GCC optimize("unroll-loops,Ofast")
#pragma GCC target("avx2,tune=native")
using namespace std;
#define int long long
#define pii pair<int,int>
#define bg begin
#define vi vector<int>
#define endl '\n'
#define vvi vector<vi>
#define pc __builtin_popcountll
#define vp vector<pii>
#define sp << " " <<
#define all(x) x.bg()+1,x.end()
#define ff first
#define ss second
#define brake {cout << "OK\n";return;}
#define debug(x) {cout << #x << ": "; for (auto it : x) cout << it << " ";cout << endl;}
#define FF(xxx,sss,yyy) for (int xxx=sss;xxx<=yyy;++xxx)
#define F(xx,yy) for (int xx=1;xx<=yy;++xx)
#define pb push_back
const int inf = 1e18;
const int MOD = 998244353;
const int N = 2e5+1;
string printyear(int year) {
string ss = to_string(year);
while (ss.size() < 4) {
ss = "0"+ss;
}
string ans;
ans+=ss[3];
ans+=ss[2];
ans+='.';
ans+=ss[1];
ans+=ss[0];
ans+='.';
ans+=ss;
ans+='.';
return ans;
}
void solve() {
int q;
cin >> q;
vector<int> goodyears;
vi cap(13);
cap = {0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31};
for (int y=0;y<=9999;y++) {
string s = to_string(y);
while (s.size() < 4) s = "0"+s;
string month;
month+=s[1];
month+=s[0];
if (stoi(month) > 12 || !stoi(month)) continue;
string day;
day+=s[3];
day+=s[2];
if (y%4 == 0) cap[2]++;
int m = stoi(month);
int d = stoi(day);
if (d>cap[m] || !stoi(day)) {
if (y%4 == 0) cap[2]--;
continue;
}
if (y%4 == 0) cap[2]--;
goodyears.pb(y);
//cout << printyear(y) << endl;
}
while (q--) {
string s;
cin >> s;
string year;
year+=s[6];
year+=s[7];
year+=s[8];
year+=s[9];
int y = stoi(year);
int x = *lower_bound(goodyears.bg(),goodyears.end(),y);
int x2 = *upper_bound(goodyears.bg(),goodyears.end(),y);
if (printyear(x) <= s) {
cout << printyear(x2) << endl;
}else cout << printyear(x) << endl;
}
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef Local
freopen("input.in", "r", stdin);
freopen("input.out", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
Compilation message
datum.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
2 | #pragma optimize "DostSeferoğlu"
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
5 ms |
564 KB |
Output isn't correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |