結果

問題 No.945 YKC饅頭
ユーザー 37zigen37zigen
提出日時 2019-12-06 01:46:03
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,085 ms / 2,000 ms
コード長 2,356 bytes
コンパイル時間 3,830 ms
コンパイル使用メモリ 85,036 KB
実行使用メモリ 72,580 KB
最終ジャッジ日時 2023-08-24 19:35:00
合計ジャッジ時間 49,729 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
41,080 KB
testcase_01 AC 161 ms
40,484 KB
testcase_02 AC 213 ms
42,304 KB
testcase_03 AC 246 ms
44,120 KB
testcase_04 AC 199 ms
42,224 KB
testcase_05 AC 219 ms
42,644 KB
testcase_06 AC 219 ms
42,432 KB
testcase_07 AC 222 ms
42,820 KB
testcase_08 AC 180 ms
40,932 KB
testcase_09 AC 216 ms
43,388 KB
testcase_10 AC 216 ms
43,556 KB
testcase_11 AC 215 ms
42,208 KB
testcase_12 AC 211 ms
42,072 KB
testcase_13 AC 242 ms
44,264 KB
testcase_14 AC 233 ms
44,444 KB
testcase_15 AC 223 ms
42,552 KB
testcase_16 AC 213 ms
42,708 KB
testcase_17 AC 243 ms
44,256 KB
testcase_18 AC 228 ms
43,488 KB
testcase_19 AC 166 ms
41,108 KB
testcase_20 AC 210 ms
42,316 KB
testcase_21 AC 208 ms
42,300 KB
testcase_22 AC 242 ms
45,196 KB
testcase_23 AC 244 ms
44,920 KB
testcase_24 AC 237 ms
45,120 KB
testcase_25 AC 241 ms
44,392 KB
testcase_26 AC 242 ms
44,716 KB
testcase_27 AC 162 ms
40,720 KB
testcase_28 AC 161 ms
40,888 KB
testcase_29 AC 161 ms
40,840 KB
testcase_30 AC 160 ms
40,596 KB
testcase_31 AC 366 ms
47,176 KB
testcase_32 AC 286 ms
52,668 KB
testcase_33 AC 619 ms
52,576 KB
testcase_34 AC 866 ms
54,184 KB
testcase_35 AC 992 ms
59,588 KB
testcase_36 AC 922 ms
65,676 KB
testcase_37 AC 900 ms
50,564 KB
testcase_38 AC 893 ms
51,028 KB
testcase_39 AC 559 ms
48,812 KB
testcase_40 AC 505 ms
54,284 KB
testcase_41 AC 360 ms
48,664 KB
testcase_42 AC 966 ms
51,848 KB
testcase_43 AC 894 ms
50,024 KB
testcase_44 AC 913 ms
59,536 KB
testcase_45 AC 1,004 ms
52,580 KB
testcase_46 AC 294 ms
48,176 KB
testcase_47 AC 858 ms
55,228 KB
testcase_48 AC 505 ms
47,004 KB
testcase_49 AC 633 ms
52,072 KB
testcase_50 AC 1,013 ms
51,896 KB
testcase_51 AC 1,034 ms
58,544 KB
testcase_52 AC 1,085 ms
60,180 KB
testcase_53 AC 1,032 ms
57,524 KB
testcase_54 AC 1,082 ms
62,184 KB
testcase_55 AC 1,039 ms
72,580 KB
testcase_56 AC 208 ms
57,600 KB
testcase_57 AC 205 ms
48,772 KB
testcase_58 AC 931 ms
53,820 KB
testcase_59 AC 997 ms
53,932 KB
testcase_60 AC 705 ms
53,992 KB
testcase_61 AC 968 ms
53,900 KB
testcase_62 AC 939 ms
53,704 KB
testcase_63 AC 280 ms
49,280 KB
testcase_64 AC 732 ms
53,484 KB
testcase_65 AC 675 ms
52,432 KB
testcase_66 AC 653 ms
51,724 KB
testcase_67 AC 861 ms
53,488 KB
testcase_68 AC 709 ms
53,768 KB
testcase_69 AC 487 ms
49,532 KB
testcase_70 AC 529 ms
49,312 KB
testcase_71 AC 537 ms
49,268 KB
testcase_72 AC 811 ms
53,440 KB
testcase_73 AC 987 ms
54,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
    
    class DJSet{
        int n;
        int[] upper;
        int[] ma;
        int[] mi;
        int[] cols;
        
        public DJSet(int n){
            this.n=n;
            upper=new int[n];
            ma=new int[n];
            mi=new int[n];
            cols=new int[n];
            Arrays.fill(upper,-1);
            Arrays.fill(cols,-1);
            for(int i=0;i<n;++i){
                ma[i]=i;
                mi[i]=i;
            }
        }
        
        //[l,r)
        void paint(int l, int r, int col){
            if(l>=r)return;
            if(cols[l]!=-1){
                paint(ma[root(l)]+1,r,col);
            }else{
                cols[l]=col;
                paint(l+1,r,col);
            }
            setUnion(l,r-1);
        }
        
        boolean equiv(int a, int b){
            return root(a)==root(b);
        }
        
        int root(int x){
            return upper[x]<0?x:(upper[x]=root(upper[x]));
        }
        
        void setUnion(int x,int y){
            x=root(x);
            y=root(y);
            if(x==y)return;
            if(upper[x]<upper[y]){
                x^=y;y^=x;x^=y;
            }
            upper[y]+=upper[x];
            upper[x]=y;
            ma[y]=Math.max(ma[y],ma[x]);
            mi[y]=Math.min(mi[y],mi[x]);
        }
    }
    
    void run() {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        DJSet ds=new DJSet(N);
        for(int i=0;i<M;++i){
            int L=sc.nextInt();
            int R=sc.nextInt();
            --L;--R;
            String T=sc.next();
            int col=-1;
            if(T.equals("Y")){
                col=0;
            }else if(T.equals("K")){
                col=1;
            }else if(T.equals("C")){
                col=2;
            }else{
                throw new AssertionError();
            }
            ds.paint(L,R+1,col);
        }
        int[] cnt=new int[3];
        for(int i=0;i<N;++i){
            if(ds.cols[i]!=-1)
                cnt[ds.cols[i]]++;
        }
        System.out.println(cnt[0]+" "+cnt[1]+" "+cnt[2]);
    }
    
    void tr(Object...objects){
        System.out.println(Arrays.deepToString(objects));
    }
}
0