import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.StringTokenizer;
class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
class Utility {
public static int sn(String s) {
int ret = 0;
for(int i = 0; i < s.length(); i++) {
ret *= 10;
ret += ( (s.charAt(i))-'0');
}
return ret;
}
}
class date implements Comparator<String> {
public int compare(String ca, String cb) {
String sYearA = "" + ca.charAt(4) + ca.charAt(5) + ca.charAt(6) + ca.charAt(7);
String sYearB = "" + cb.charAt(4) + cb.charAt(5) + cb.charAt(6) + cb.charAt(7);
String sMonthA = "" + ca.charAt(2) + ca.charAt(3);
String sMonthB = "" + cb.charAt(2) + cb.charAt(3);
String sDayA = "" + ca.charAt(0) + ca.charAt(1);
String sDayB = "" + cb.charAt(0) + cb.charAt(1);
int nYearA = Utility.sn(sYearA);
int nYearB = Utility.sn(sYearB);
int nMonthA = Utility.sn(sMonthA);
int nMonthB = Utility.sn(sMonthB);
int nDayA = Utility.sn(sDayA);
int nDayB = Utility.sn(sDayB);
if(nYearA==nYearB) {
if(nMonthA==nMonthB)
return Integer.compare(nDayA, nDayB);
return Integer.compare(nMonthA, nMonthB);
}
return Integer.compare(nYearA, nYearB);
}
}
class Pair implements Comparable<Pair> {
String s;
int ind;
Pair(String s, int ind) {
this.s = s;
this.ind = ind;
}
public int compareTo(Pair o) {
String ca = s;
String cb = o.s;
String sYearA = "" + ca.charAt(4) + ca.charAt(5) + ca.charAt(6) + ca.charAt(7);
String sYearB = "" + cb.charAt(4) + cb.charAt(5) + cb.charAt(6) + cb.charAt(7);
String sMonthA = "" + ca.charAt(2) + ca.charAt(3);
String sMonthB = "" + cb.charAt(2) + cb.charAt(3);
String sDayA = "" + ca.charAt(0) + ca.charAt(1);
String sDayB = "" + cb.charAt(0) + cb.charAt(1);
int nYearA = Utility.sn(sYearA);
int nYearB = Utility.sn(sYearB);
int nMonthA = Utility.sn(sMonthA);
int nMonthB = Utility.sn(sMonthB);
int nDayA = Utility.sn(sDayA);
int nDayB = Utility.sn(sDayB);
if(nYearA==nYearB) {
if(nMonthA==nMonthB)
return Integer.compare(nDayA, nDayB);
return Integer.compare(nMonthA, nMonthB);
}
return Integer.compare(nYearA, nYearB);
}
}
public class datum {
public static int cmp(String ca, String cb) {
String sYearA = "" + ca.charAt(4) + ca.charAt(5) + ca.charAt(6) + ca.charAt(7);
String sYearB = "" + cb.charAt(4) + cb.charAt(5) + cb.charAt(6) + cb.charAt(7);
String sMonthA = "" + ca.charAt(2) + ca.charAt(3);
String sMonthB = "" + cb.charAt(2) + cb.charAt(3);
String sDayA = "" + ca.charAt(0) + ca.charAt(1);
String sDayB = "" + cb.charAt(0) + cb.charAt(1);
int nYearA = Utility.sn(sYearA);
int nYearB = Utility.sn(sYearB);
int nMonthA = Utility.sn(sMonthA);
int nMonthB = Utility.sn(sMonthB);
int nDayA = Utility.sn(sDayA);
int nDayB = Utility.sn(sDayB);
if(nYearA==nYearB) {
if(nMonthA==nMonthB)
return Integer.compare(nDayA, nDayB);
return Integer.compare(nMonthA, nMonthB);
}
return Integer.compare(nYearA, nYearB);
}
public static void main(String[] args) {
int days[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ArrayList<String> listPalindromicDates = new ArrayList<String>();
ArrayList<Pair> listDates = new ArrayList<Pair>();
for(int month = 1; month < days.length; month++) {
for(int day = 1; day <= days[month]; day++) {
String sday = String.valueOf(day);
if(sday.length()==1) sday = '0' + sday;
String smonth = String.valueOf(month);
if(smonth.length()==1) smonth = '0' + smonth;
String syear = sday + smonth;
syear = new StringBuffer(syear).reverse().toString();
listPalindromicDates.add(sday + smonth + syear);
if(month==2 && day==28) {
int new_day = day + 1;
sday = String.valueOf(new_day);
if(sday.length()==1) sday = '0' + sday;
smonth = String.valueOf(month);
if(smonth.length()==1) smonth = '0' + smonth;
syear = sday + smonth;
syear = new StringBuffer(syear).reverse().toString();
listPalindromicDates.add(sday + smonth + syear);
}
}
}
Collections.sort(listPalindromicDates, new date());
MyScanner input = new MyScanner();
int n = input.nextInt();
for(int i = 0; i < n; i++) {
String D = input.next();
D = D.replace(".", "");
listDates.add(new Pair(D, i));
}
Collections.sort(listDates);
int index = 0;
String[] sarrAnswer = new String[n];
for(int i = 0; i < listDates.size(); i++) {
while(index < listPalindromicDates.size() && (cmp(listDates.get(i).s, listPalindromicDates.get(index)) >= 0 ) ) index++;
sarrAnswer[listDates.get(i).ind] = ( listPalindromicDates.get(index).substring(0, 2) + "." + listPalindromicDates.get(index).substring(2, 4) + "." + listPalindromicDates.get(index).substring(4, 8) + "." );
}
for(int i = 0; i < n; i++)
System.out.println(sarrAnswer[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
15752 KB |
Output is correct |
2 |
Execution timed out |
1104 ms |
66568 KB |
Time limit exceeded |
3 |
Correct |
142 ms |
15384 KB |
Output is correct |
4 |
Correct |
148 ms |
16248 KB |
Output is correct |
5 |
Correct |
138 ms |
15108 KB |
Output is correct |
6 |
Correct |
159 ms |
15364 KB |
Output is correct |
7 |
Correct |
138 ms |
15464 KB |
Output is correct |
8 |
Correct |
107 ms |
12428 KB |
Output is correct |
9 |
Correct |
131 ms |
15900 KB |
Output is correct |
10 |
Execution timed out |
1112 ms |
73280 KB |
Time limit exceeded |