Submission #845454

# Submission time Handle Problem Language Result Execution time Memory
845454 2023-09-06T13:40:17 Z vjudge1 Datum (COCI20_datum) C++17
50 / 50
697 ms 90448 KB
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n" 
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()


bool is_palindrome(string s){
	string res=s;
	reverse(all(res));
	return res==s;
}

vector<char> go(int d){
  vector<char> res;
  while(d){
  	res.pb('0'+d%10);
  	d/=10;
  }
  reverse(all(res));
  return res;
}


bool check(int d,int m,int y){
   if(d>31 || m>12) return 0;
   if(m==0 || d==0 || y==0) return 0;
   
   if(m==2){
   	 if(d>29) return 0;
   	 if(y%4!=0 && d==29) return 0; 
   }
   else if(m==4 && d>30) return 0;
   else if(m==6 && d>30) return 0;
   else if(m==9 && d>30) return 0;
   else if(m==11 && d>30) return 0;

   return 1;
}

bool valid(int d,int m,int y){
   string s="";
   vector<char> cur=go(d);
   if(sz(cur)<2) s.pb('0');
   for(char x:cur) s.pb(x);
   cur=go(m);
   if(sz(cur)<2) s.pb('0');
   for(char x:cur) s.pb(x);
   cur=go(y);
   if(sz(cur)<4){ 
   	 for(int xd=0;xd<4-sz(cur);xd++) s.pb('0');
   }
   for(char x:cur) s.pb(x);
   if(!is_palindrome(s)) return 0;
   return 1;
}


void solve(){
  
  array<int,3> dp[32][13][9195];
  
  array<int,3> last={-1,-1,-1};
  for(int y=9194;y>=1;y--){
  	for(int m=12;m>=1;m--){
  		for(int d=31;d>=1;d--){
  		   if(!check(d,m,y)) continue;
           if(last[0]==-1) dp[d][m][y]=last;
           else if(valid(last[0],last[1],last[2])) dp[d][m][y]=last;
           else dp[d][m][y]=dp[last[0]][last[1]][last[2]];
           last={d,m,y};
  		}
  	}
  }

  int q;
  cin >> q;
  
  while(q--){
  	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';
  	if(dp[d][m][y][0]<10) cout << 0;
  	cout << dp[d][m][y][0] << '.';
  	if(dp[d][m][y][1]<10) cout << 0;
  	cout << dp[d][m][y][1] << '.';
  	if(dp[d][m][y][2]<1000) cout << 0;
  	if(dp[d][m][y][2]<100) cout << 0;
  	if(dp[d][m][y][2]<10) cout << 0;
  	cout << dp[d][m][y][2] << '.' << endl;
  }
}

int32_t main(){

  cin.tie(0); ios::sync_with_stdio(0);
  
  int t=1;//cin >> t;
  while(t--) solve();

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 639 ms 90448 KB Output is correct
2 Correct 697 ms 90252 KB Output is correct
3 Correct 651 ms 90176 KB Output is correct
4 Correct 664 ms 90192 KB Output is correct
5 Correct 648 ms 90448 KB Output is correct
6 Correct 656 ms 90252 KB Output is correct
7 Correct 647 ms 90448 KB Output is correct
8 Correct 694 ms 90448 KB Output is correct
9 Correct 646 ms 90252 KB Output is correct
10 Correct 640 ms 90256 KB Output is correct