結果
問題 |
No.230 Splarraay スプラレェーイ
|
ユーザー |
![]() |
提出日時 | 2016-10-30 18:43:01 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,315 bytes |
コンパイル時間 | 2,668 ms |
コンパイル使用メモリ | 80,472 KB |
実行使用メモリ | 141,316 KB |
最終ジャッジ日時 | 2024-11-24 23:50:07 |
合計ジャッジ時間 | 45,732 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 TLE * 5 |
ソースコード
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; class C{ static Scanner s = new Scanner(System.in); static Stage stage; static ArrayList<ArrayList<Event>> events = new ArrayList<ArrayList<Event>>(); static boolean[] updated; static int updatedcount; @SuppressWarnings("unchecked") public static void main(String[] args){ stage = new Stage(Integer.parseInt(s.next())); s.next(); ArrayList<Event> finalevents; ArrayList<Event> list = new ArrayList<Event>(); while(s.hasNext()) { Event e = new Event(Byte.parseByte(s.next()), Integer.parseInt(s.next()), Integer.parseInt(s.next())); list.add(e); if(e.type==State.N) { events.add((ArrayList<Event>) list.clone()); list.clear();; } } finalevents=list; updated = new boolean[stage.stage.length]; for(ArrayList<Event> l:events) { Event bonus_e = l.remove(l.size()-1); paint(l); stage.addBonus(bonus_e.l, bonus_e.r); } if(!finalevents.isEmpty()) paint(finalevents); stage.finish(); System.out.print(stage.scoreA); System.out.print(" "); System.out.println(stage.scoreB); } static void paint(List<Event> l) { updatedcount = stage.stage.length; Arrays.fill(updated, false); for(int i=l.size()-1;i>=0;--i) { Event e = l.get(i); for(int ii=e.l;ii<=e.r;ii++) { if(!updated[ii]) { updated[ii]=true; stage.stage[ii] = e.type; if(--updatedcount==0) break; } } } } } class Stage{ long scoreA=0,scoreB=0; State[] stage; Stage(int size){ stage=new State[size]; Arrays.fill(stage, State.N); } void addBonus(int l,int r) { int a=0,b=0; for(int i=l;i<=r;i++) { State s=stage[i]; if(s!=State.N) { if(s==State.A) { a++; }else { b++; } } } if(a>b) { scoreA += Math.max(a, b); }else if(a<b) { scoreB += Math.max(a, b); } } void finish() { for(State s:stage) { if(s!=State.N) { if(s==State.A) { scoreA++; }else { scoreB++; } } } } } class Event{ State type; int l,r; Event(byte type, int l, int r){ this.type = State.get(type); this.l = l; this.r = r; } } enum State{ N,A,B; static State get(byte v) { if(v==0) { return N; }else if(v==1) { return A; }else { return B; } } }