結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー 37zigen37zigen
提出日時 2020-04-13 06:19:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 888 ms / 1,000 ms
コード長 1,800 bytes
コンパイル時間 3,861 ms
コンパイル使用メモリ 83,508 KB
実行使用メモリ 90,964 KB
最終ジャッジ日時 2023-10-24 11:12:30
合計ジャッジ時間 19,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 842 ms
90,212 KB
testcase_01 AC 871 ms
90,068 KB
testcase_02 AC 281 ms
68,748 KB
testcase_03 AC 289 ms
68,652 KB
testcase_04 AC 318 ms
68,552 KB
testcase_05 AC 237 ms
67,564 KB
testcase_06 AC 308 ms
68,564 KB
testcase_07 AC 286 ms
68,584 KB
testcase_08 AC 287 ms
68,540 KB
testcase_09 AC 237 ms
68,104 KB
testcase_10 AC 239 ms
67,732 KB
testcase_11 AC 332 ms
68,100 KB
testcase_12 AC 839 ms
89,116 KB
testcase_13 AC 888 ms
86,564 KB
testcase_14 AC 857 ms
88,836 KB
testcase_15 AC 871 ms
89,364 KB
testcase_16 AC 870 ms
89,476 KB
testcase_17 AC 813 ms
88,484 KB
testcase_18 AC 864 ms
90,820 KB
testcase_19 AC 855 ms
90,964 KB
testcase_20 AC 878 ms
86,580 KB
testcase_21 AC 855 ms
89,728 KB
testcase_22 AC 868 ms
90,452 KB
testcase_23 AC 488 ms
69,300 KB
testcase_24 AC 229 ms
67,544 KB
testcase_25 AC 228 ms
67,720 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]=Integer.parseInt(sc.next());
			A[i]=Integer.parseInt(sc.next());
			B[i]=Integer.parseInt(sc.next());
		}
		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