結果

問題 No.230 Splarraay スプラレェーイ
ユーザー fal_rndfal_rnd
提出日時 2016-10-30 17:26:25
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,201 bytes
コンパイル時間 2,534 ms
コンパイル使用メモリ 80,384 KB
実行使用メモリ 76,796 KB
最終ジャッジ日時 2024-05-03 19:53:26
合計ジャッジ時間 18,098 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
41,936 KB
testcase_01 AC 119 ms
41,912 KB
testcase_02 AC 119 ms
41,124 KB
testcase_03 AC 105 ms
41,456 KB
testcase_04 AC 123 ms
41,232 KB
testcase_05 AC 206 ms
43,996 KB
testcase_06 AC 430 ms
48,444 KB
testcase_07 AC 204 ms
44,204 KB
testcase_08 AC 250 ms
46,820 KB
testcase_09 AC 2,179 ms
62,304 KB
testcase_10 AC 945 ms
65,584 KB
testcase_11 AC 1,180 ms
59,948 KB
testcase_12 AC 1,910 ms
62,600 KB
testcase_13 AC 499 ms
48,544 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

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