結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー 37zigen37zigen
提出日時 2020-04-13 06:17:14
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,755 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 80,076 KB
実行使用メモリ 94,424 KB
最終ジャッジ日時 2023-10-24 11:07:02
合計ジャッジ時間 21,946 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 952 ms
92,784 KB
testcase_01 AC 974 ms
93,592 KB
testcase_02 AC 285 ms
68,512 KB
testcase_03 AC 294 ms
68,244 KB
testcase_04 AC 313 ms
68,648 KB
testcase_05 AC 235 ms
67,876 KB
testcase_06 AC 312 ms
68,452 KB
testcase_07 AC 297 ms
68,520 KB
testcase_08 AC 291 ms
66,156 KB
testcase_09 AC 241 ms
67,816 KB
testcase_10 AC 239 ms
67,528 KB
testcase_11 AC 329 ms
68,604 KB
testcase_12 AC 942 ms
93,116 KB
testcase_13 TLE -
testcase_14 AC 901 ms
92,476 KB
testcase_15 AC 999 ms
92,444 KB
testcase_16 AC 908 ms
93,312 KB
testcase_17 AC 937 ms
94,092 KB
testcase_18 AC 999 ms
91,024 KB
testcase_19 AC 938 ms
94,424 KB
testcase_20 AC 943 ms
90,792 KB
testcase_21 AC 921 ms
92,484 KB
testcase_22 TLE -
testcase_23 AC 439 ms
67,136 KB
testcase_24 AC 244 ms
68,288 KB
testcase_25 AC 241 ms
67,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	void solve(int N,int M,int[] X,int[] A,int[] B) {
		ArrayList<Integer>[][] list=new ArrayList[2][100001];
		for (int i=0;i<list.length;++i) 
			for (int j=0;j<list[i].length;++j) list[i][j]=new ArrayList<>();
		int over3=0;
		int over2=0;
		for (int i=0;i<N;++i) {
			if (X[i]+1>=2) ++over2;
			if (X[i]+1>=3) ++over3;
			list[0][A[i]].add(i);
			list[1][B[i]].add(i);
		}
		int[] solve=new int[N];
		Arrays.fill(solve, 1);
		int sb=0;
		int sa=100001;
		int ans=Integer.MAX_VALUE/3;
		while(true) {
			while (sb<=100000) { // over2>=Mが成り立つギリギリまでsbを大きくする。
				int nover2=over2;
				int nover3=over3;
				for (int i:list[1][sb]) {
					if (solve[i]+X[i]==2) --nover2;
					if (solve[i]+X[i]==3) --nover3;
				}
				if (nover2>=M) {
					over2=nover2;
					over3=nover3;
					for (int i:list[1][sb]) --solve[i];
					++sb;
				} else {
					break;
				}
				if (over2>=M) ans=Math.min(ans, over3);
			}
			--sa;
			if (sa==-1) break;
			for (int i:list[0][sa]) {
				if (solve[i]+X[i]==1) ++over2;
				if (solve[i]+X[i]==2) ++over3;
				++solve[i];
			}
		}
		System.out.println(ans);
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int[] X=new int[N];
		int[] A=new int[N];
		int[] B=new int[N];
		for (int i=0;i<N;++i) {
			X[i]=sc.nextInt();
			A[i]=sc.nextInt();
			B[i]=sc.nextInt();
		}
		solve(N,M,X,A,B);
		pw.close();
	} 
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
    public static void main(String[] args) {
    	new Main().run();
    }
}
0