Submission #657224
Source Code Expand
import java.io.InputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; import java.util.NoSuchElementException; import java.math.BigInteger; public class Main{ static PrintWriter out; static InputReader ir; static void solve(){ int n=ir.nextInt(); ArrayList<int[]> seg=new ArrayList<>(); for(int i=0;i<n;i++){ String t=ir.next(); int m=Integer.parseInt(t.substring(0,2)); int s=Integer.parseInt(t.substring(2)); s-=s%5; t=ir.next(); int mm=Integer.parseInt(t.substring(0,2)); int ss=Integer.parseInt(t.substring(2)); if(ss%5!=0) ss+=5-ss%5; seg.add(new int[]{m*60+s,mm*60+ss}); } UniteSegmentsAndGetTotalLength(seg,1); for(int[] r : seg){ for(int i=0;i<2;i++){ int a=r[i]/60,b=r[i]%60; out.print((a<10?"0":"")+a+(b<10?"0":"")+b); if(i==0) out.print("-"); else out.println(); } } } static long UniteSegmentsAndGetTotalLength(ArrayList<int[]> seg,int k){ int n=seg.size(); Point[] ps=new Point[2*n]; for(int i=0;i<n;i++){ int[] s=seg.get(i); ps[2*i]=new Point(s[0],true); ps[2*i+1]=new Point(s[1],false); } seg.clear(); Arrays.sort(ps,new Comparator<Point>(){ public int compare(Point a,Point b){ if(a.pos!=b.pos) return Integer.compare(a.pos,b.pos); if(a.isLeftSide==b.isLeftSide) return 0; if(a.isLeftSide) return -1; return 1; } }); int cur=0,l=-1; long ret=0; boolean f=false; for(int i=0;i<2*n;i++){ cur+=ps[i].isLeftSide?1:-1; if(cur>=k&&!f){ f=true; l=ps[i].pos; } else if(cur<k&&f){ f=false; if(l!=ps[i].pos) seg.add(new int[]{l,ps[i].pos}); ret+=ps[i].pos-l; } } return ret; } static class Point{ public int pos; public boolean isLeftSide; public Point(int pos,boolean isLeftSide){ this.pos=pos; this.isLeftSide=isLeftSide; } } public static void main(String[] args) throws Exception{ ir=new InputReader(System.in); out=new PrintWriter(System.out); solve(); out.flush(); } static class InputReader { private InputStream in; private byte[] buffer=new byte[1024]; private int curbuf; private int lenbuf; public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;} public boolean hasNextByte() { if(curbuf>=lenbuf){ curbuf= 0; try{ lenbuf=in.read(buffer); }catch(IOException e) { throw new InputMismatchException(); } if(lenbuf<=0) return false; } return true; } private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;} private boolean isSpaceChar(int c){return !(c>=33&&c<=126)||c=='-';} private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;} public boolean hasNext(){skip(); return hasNextByte();} public String next(){ if(!hasNext()) throw new NoSuchElementException(); StringBuilder sb=new StringBuilder(); int b=readByte(); while(!isSpaceChar(b)){ sb.appendCodePoint(b); b=readByte(); } return sb.toString(); } public int nextInt() { if(!hasNext()) throw new NoSuchElementException(); int c=readByte(); while (isSpaceChar(c)) c=readByte(); boolean minus=false; if (c=='-') { minus=true; c=readByte(); } int res=0; do{ if(c<'0'||c>'9') throw new InputMismatchException(); res=res*10+c-'0'; c=readByte(); }while(!isSpaceChar(c)); return (minus)?-res:res; } public long nextLong() { if(!hasNext()) throw new NoSuchElementException(); int c=readByte(); while (isSpaceChar(c)) c=readByte(); boolean minus=false; if (c=='-') { minus=true; c=readByte(); } long res = 0; do{ if(c<'0'||c>'9') throw new InputMismatchException(); res=res*10+c-'0'; c=readByte(); }while(!isSpaceChar(c)); return (minus)?-res:res; } public double nextDouble(){return Double.parseDouble(next());} public int[] nextIntArray(int n){ int[] a=new int[n]; for(int i=0;i<n;i++) a[i]=nextInt(); return a; } public long[] nextLongArray(int n){ long[] a=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } public char[][] nextCharMap(int n,int m){ char[][] map=new char[n][m]; for(int i=0;i<n;i++) map[i]=next().toCharArray(); return map; } } }
Submission Info
Submission Time | |
---|---|
Task | D - 感雨時刻の整理 |
User | holeguma |
Language | Java (OpenJDK 1.7.0) |
Score | 100 |
Code Size | 4421 Byte |
Status | AC |
Exec Time | 710 ms |
Memory | 36780 KB |
Judge Result
Set Name | all | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
all | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, cho_cho_chokudai.txt, chokudai_ga_cho.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 301 ms | 20868 KB |
00_sample_02.txt | AC | 292 ms | 20852 KB |
00_sample_03.txt | AC | 293 ms | 20852 KB |
cho_cho_chokudai.txt | AC | 548 ms | 33808 KB |
chokudai_ga_cho.txt | AC | 626 ms | 36240 KB |
test_01.txt | AC | 301 ms | 20988 KB |
test_02.txt | AC | 303 ms | 20984 KB |
test_03.txt | AC | 303 ms | 20928 KB |
test_04.txt | AC | 299 ms | 20912 KB |
test_05.txt | AC | 310 ms | 21024 KB |
test_06.txt | AC | 346 ms | 20972 KB |
test_07.txt | AC | 303 ms | 20976 KB |
test_08.txt | AC | 299 ms | 20876 KB |
test_09.txt | AC | 322 ms | 21752 KB |
test_10.txt | AC | 321 ms | 21952 KB |
test_11.txt | AC | 316 ms | 21104 KB |
test_12.txt | AC | 315 ms | 21048 KB |
test_13.txt | AC | 307 ms | 20924 KB |
test_14.txt | AC | 320 ms | 21772 KB |
test_15.txt | AC | 322 ms | 21884 KB |
test_16.txt | AC | 335 ms | 21024 KB |
test_17.txt | AC | 333 ms | 21680 KB |
test_18.txt | AC | 309 ms | 21048 KB |
test_19.txt | AC | 318 ms | 21144 KB |
test_20.txt | AC | 319 ms | 21144 KB |
test_21.txt | AC | 710 ms | 36780 KB |
test_22.txt | AC | 666 ms | 36440 KB |
test_23.txt | AC | 661 ms | 36248 KB |
test_24.txt | AC | 695 ms | 36332 KB |
test_25.txt | AC | 602 ms | 35792 KB |
test_26.txt | AC | 634 ms | 35544 KB |
test_27.txt | AC | 536 ms | 33576 KB |
test_28.txt | AC | 677 ms | 36608 KB |
test_29.txt | AC | 298 ms | 20880 KB |
test_30.txt | AC | 293 ms | 20928 KB |
test_31.txt | AC | 410 ms | 25892 KB |
test_32.txt | AC | 291 ms | 20868 KB |
test_33.txt | AC | 559 ms | 34316 KB |
test_34.txt | AC | 292 ms | 20844 KB |
test_35.txt | AC | 304 ms | 21028 KB |
test_36.txt | AC | 648 ms | 35976 KB |
test_37.txt | AC | 650 ms | 36016 KB |
test_38.txt | AC | 668 ms | 36304 KB |
test_39.txt | AC | 628 ms | 35936 KB |
test_40.txt | AC | 613 ms | 35392 KB |
test_41.txt | AC | 538 ms | 33200 KB |
test_42.txt | AC | 642 ms | 36164 KB |
test_43.txt | AC | 522 ms | 33344 KB |