// Imagine not FFT
#include <bits/stdc++.h>
#define ONLINE_JUDGE
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#ifndef ONLINE_JUDGE
#define DEBUG(x) std::cerr << #x << ": " << x << std::endl;
#define DEBUGV(x) std::cerr << #x << ": { "; for(auto ___y:x) std::cerr << ___y << " "; std::cerr << "}" << std::endl;
#define DEBUGVV(x) std::cerr << #x << ": { \n"; for(int _i=0;_i<sz(x);++_i) {DEBUGV(x[_i]);} std::cerr << "}" << std::endl;
#define DEBUGVP(x) std::cerr << #x << ": { "; for(auto ___y:x) std::cerr << "{" << ___y.first << "," << ___y.second << "}" << " "; std::cerr << "}" << std::endl;
#define files freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define fastio std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr);
#else
#define fastio std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr);
#define DEBUG(...) void(23)
#define DEBUGV(x) void(23);
#define DEBUGARR(arr, size) void(23)
#define DEBUGPRINT(...) void(23)
#define DEBUGMAP(...) void(23)
#define DEBUGMAPQUEUE(...) void(23)
#define DEBUGVV(x) void(23);
#define DEBUGVP(x) void(23);
#define files void(23);
#endif
#define int long long
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pii std::pair < int , int >
#define pll std::pair < ll , ll >
#define vi std::vector < ll >
#define vl std::vector < int >
#define vii std::vector < pii >
#define vll std::vector < pll >
#define vvi std::vector < vi >
#define vvii std::vector < vii >
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define forn(i,j) for(int i=0;i<j;i++)
#define forr(i,j,k) for(int i=j;i<k;i++)
#define mset multiset
#define pqueue priority_queue
#define cmax(a,b) (a = max(a,b))
#define cmin(a,b) (a = min(a,b))
#define sz(a) (int)(a.size())
const int MOD = 1000000007;
const int MOD2 = 998244353;
using namespace std;
#define il(x) (x%400==0 || (x%4==0 && x%100!=0))
#define yd(x) (x%10*10+x/10%10)
#define ym(x) (x/100%10*10+x/1000%10)
vi day = {31,28,31,30,31,30,31,31,30,31,30,31};
bool check(int y){
if(y==2092) return true;
int m=ym(y);
int d=yd(y);
if(m>12) return false;
if(m==0) return false;
if(d>day[m-1]) return false;
if(d==0) return false;
return true;
}
vi nxt(10000,-1);
void init(){
int last=-1;
for(int i=9999;i>=0;i--){
if(check(i)) last=i;
nxt[i]=last;
}
}
void solve(int _t_case){
string s;
cin >> s;
int d = (s[0]-'0')*10+(s[1]-'0');
int m = (s[3]-'0')*10+(s[4]-'0');
int y = (s[6]-'0')*1000+(s[7]-'0')*100+(s[8]-'0')*10+(s[9]-'0');
int a=y;
if(ym(a)<m || (ym(a)==m && yd(a)<=d)) ++a;
//cerr << ym(2345) << " " << yd(2345) << endl;
//while(a!=2092 && ( (ym(a)>12 || yd(a)>day[ym(a)]) || (ym(a)==0 || yd(a)==0) )) ++a;
a=nxt[a];
DEBUG(a);
DEBUG(yd(a));
DEBUG(ym(a));
string _d=to_string(yd(a));
string _m=to_string(ym(a));
string _a=to_string((a));
while(_d.size()<2) _d="0"+_d;
while(_m.size()<2) _m="0"+_m;
while(_a.size()<4) _a="0"+_a;
cout << _d << '.' << _m << '.' << _a << '.' << endl;
return;
}
signed main(){
init();
fastio;
files;
int t=1,_t=0;
std::cin >> t;
while(_t<t){
++_t;
solve(_t);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
16 ms |
652 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
16 ms |
564 KB |
Output is correct |