結果

問題 No.497 入れ子の箱
ユーザー zimpha
提出日時 2017-03-25 18:20:45
言語 Java
(openjdk 23)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 2,761 bytes
コンパイル時間 1,788 ms
コンパイル使用メモリ 78,548 KB
実行使用メモリ 52,924 KB
最終ジャッジ日時 2024-07-06 06:05:49
合計ジャッジ時間 5,830 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Chiaki.Hoshinomori
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task497 solver = new Task497();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task497 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[][] box = new int[n][];
            for (int i = 0; i < n; i++) {
                box[i] = new int[3];
                for (int j = 0; j < 3; ++j) {
                    box[i][j] = in.nextInt();
                }
                Arrays.sort(box[i]);
            }
            Arrays.sort(box, new Comparator<int[]>() {

                public int compare(int[] o1, int[] o2) {
                    if (o1[0] != o2[0]) return o1[0] - o2[0];
                    if (o1[1] != o2[1]) return o1[1] - o2[1];
                    return o1[2] - o2[2];
                }
            });
            int[] dp = new int[n];
            int ret = 0;
            for (int i = 0; i < n; i++) {
                dp[i] = 1;
                for (int j = 0; j < i; j++) {
                    if (box[j][0] < box[i][0] && box[j][1] < box[i][1] && box[j][2] < box[i][2]) {
                        dp[i] = Math.max(dp[i], dp[j] + 1);
                    }
                }
                ret = Math.max(ret, dp[i]);
            }
            out.println(ret);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

0