結果

問題 No.230 Splarraay スプラレェーイ
ユーザー fal_rnd
提出日時 2016-10-30 17:26:25
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 2,201 bytes
コンパイル時間 2,873 ms
コンパイル使用メモリ 83,756 KB
実行使用メモリ 146,472 KB
最終ジャッジ日時 2024-11-24 23:44:47
合計ジャッジ時間 47,480 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
class C{
	static Scanner s=new Scanner(System.in);


	static Stage	stage;
	static LinkedList<LinkedList<Event>> events = new LinkedList<LinkedList<Event>>();
	static boolean[] updated;
	static int       updatedcount;


	public static void main(String[] args){
		stage  = new Stage(s.nextInt());
		LinkedList<Event> finalevents;
		{
			LinkedList<Event> list = new LinkedList<Event>();
			int l = s.nextInt();
			for(int i=0;i<l;i++) {
				Event e = new Event(s.nextByte(), s.nextInt(), s.nextInt());
				list.addFirst(e);
				if(e.type==State.N) {
					events.add(list);
					list = new LinkedList<Event>();
				}
			}
			finalevents=list;
		}

		updated = new boolean[stage.stage.length];

		for(LinkedList<Event> l:events) {
			Event bonus_e = l.removeFirst();
			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(LinkedList<Event> l) {
		updatedcount = stage.stage.length;
		Arrays.fill(updated, false);
		for(Event e:l) {
			for(int i=e.l;i<=e.r;i++) {
				if(!updated[i]) {
					updated[i]=true;
					stage.stage[i] = e.type;
					--updatedcount;
				}
			}
			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++) {
			switch (stage[i]) {
			case A:
				a++;
				break;
			case B:
				b++;
				break;
			case N:
			}
		}
		if(a>b) {
			scoreA += Math.max(a, b);
		}else if(a<b) {
			scoreB += Math.max(a, b);
		}
	}
	void finish() {
		for(State s:stage) {
			switch (s) {
			case A:
				scoreA++;
				break;
			case B:
				scoreB++;
				break;
			case N:
			}
		}
	}
}
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) {
		switch (v) {
		case 0:
			return N;
		case 1:
			return A;
		case 2:
			return B;
		default:
			throw new IllegalArgumentException();
		}
	}
}
0