結果

問題 No.945 YKC饅頭
ユーザー hiromi_ayasehiromi_ayase
提出日時 2019-12-09 02:12:57
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,641 ms / 2,000 ms
コード長 3,435 bytes
コンパイル時間 2,699 ms
コンパイル使用メモリ 88,820 KB
実行使用メモリ 80,708 KB
最終ジャッジ日時 2023-09-01 03:38:26
合計ジャッジ時間 47,554 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
53,272 KB
testcase_01 AC 118 ms
53,324 KB
testcase_02 AC 132 ms
53,740 KB
testcase_03 AC 154 ms
54,788 KB
testcase_04 AC 131 ms
53,528 KB
testcase_05 AC 134 ms
53,620 KB
testcase_06 AC 153 ms
55,104 KB
testcase_07 AC 138 ms
54,036 KB
testcase_08 AC 131 ms
53,628 KB
testcase_09 AC 140 ms
53,724 KB
testcase_10 AC 137 ms
54,712 KB
testcase_11 AC 133 ms
53,568 KB
testcase_12 AC 134 ms
53,544 KB
testcase_13 AC 143 ms
56,128 KB
testcase_14 AC 152 ms
54,692 KB
testcase_15 AC 135 ms
54,440 KB
testcase_16 AC 133 ms
53,644 KB
testcase_17 AC 146 ms
54,984 KB
testcase_18 AC 141 ms
54,728 KB
testcase_19 AC 126 ms
53,580 KB
testcase_20 AC 132 ms
53,504 KB
testcase_21 AC 138 ms
53,728 KB
testcase_22 AC 152 ms
54,796 KB
testcase_23 AC 157 ms
55,304 KB
testcase_24 AC 155 ms
55,096 KB
testcase_25 AC 157 ms
55,088 KB
testcase_26 AC 145 ms
55,076 KB
testcase_27 AC 119 ms
53,592 KB
testcase_28 AC 121 ms
53,444 KB
testcase_29 AC 124 ms
53,508 KB
testcase_30 AC 121 ms
55,260 KB
testcase_31 AC 301 ms
60,584 KB
testcase_32 AC 238 ms
59,612 KB
testcase_33 AC 597 ms
63,700 KB
testcase_34 AC 1,164 ms
69,320 KB
testcase_35 AC 1,426 ms
74,292 KB
testcase_36 AC 1,338 ms
74,836 KB
testcase_37 AC 1,267 ms
75,284 KB
testcase_38 AC 1,129 ms
69,392 KB
testcase_39 AC 476 ms
59,992 KB
testcase_40 AC 458 ms
60,240 KB
testcase_41 AC 295 ms
60,300 KB
testcase_42 AC 1,352 ms
74,344 KB
testcase_43 AC 1,210 ms
73,052 KB
testcase_44 AC 1,281 ms
72,804 KB
testcase_45 AC 1,597 ms
78,672 KB
testcase_46 AC 182 ms
55,152 KB
testcase_47 AC 1,039 ms
66,500 KB
testcase_48 AC 493 ms
60,316 KB
testcase_49 AC 627 ms
63,156 KB
testcase_50 AC 1,594 ms
80,476 KB
testcase_51 AC 1,637 ms
80,292 KB
testcase_52 AC 1,564 ms
79,600 KB
testcase_53 AC 1,641 ms
79,516 KB
testcase_54 AC 1,594 ms
80,708 KB
testcase_55 AC 1,581 ms
80,360 KB
testcase_56 AC 147 ms
54,796 KB
testcase_57 AC 142 ms
54,576 KB
testcase_58 AC 857 ms
64,788 KB
testcase_59 AC 969 ms
66,896 KB
testcase_60 AC 531 ms
61,808 KB
testcase_61 AC 877 ms
65,036 KB
testcase_62 AC 833 ms
65,564 KB
testcase_63 AC 222 ms
58,256 KB
testcase_64 AC 555 ms
62,132 KB
testcase_65 AC 496 ms
61,856 KB
testcase_66 AC 469 ms
59,956 KB
testcase_67 AC 696 ms
62,064 KB
testcase_68 AC 570 ms
62,380 KB
testcase_69 AC 354 ms
60,724 KB
testcase_70 AC 385 ms
60,648 KB
testcase_71 AC 378 ms
60,640 KB
testcase_72 AC 607 ms
62,804 KB
testcase_73 AC 955 ms
65,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.TreeSet;

public class Main {

  private static void solve() {
    int n = ni();
    int m = ni();
    int[][] p = new int[m][4];
    for (int i = 0; i < m; i++) {
      p[i][0] = ni() - 1;
      p[i][1] = ni() - 1;
      char t = ns()[0];
      if (t == 'Y') {
        p[i][2] = 0;
      } else if (t == 'K') {
        p[i][2] = 1;
      } else {
        p[i][2] = 2;
      }
      p[i][3] = i;
    }

    Arrays.sort(p, (o1, o2) -> o1[0] - o2[0]);
    int ptr = 0;

    TreeSet<int[]> q1 = new TreeSet<>((o1, o2) -> o1[3] - o2[3]);
    TreeSet<int[]> q2 = new TreeSet<>((o1, o2) -> o1[1] == o2[1] ? o1[3] - o2[3] : o1[1] - o2[1]);
    int[] ret = new int[3];
    for (int i = 0; i < n; i++) {
      while (ptr < m && p[ptr][0] == i) {
        q1.add(p[ptr]);
        q2.add(p[ptr]);
        ptr++;
      }
      while (q2.size() > 0 && q2.first()[1] < i) {
        int[] x = q2.pollFirst();
        q1.remove(x);
      }
      if (q1.size() > 0)
        ret[q1.first()[2]]++;
    }

    System.out.println(ret[0] + " " + ret[1] + " " + ret[2]);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}

0