Submission #855002


Source Code Expand

Copy
// package atcoder.arc.arc060;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 * Created by hama_du on 2016/08/28.
 */
public class Main {
    private static final int MOD = (int)1e9+7;

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int a = in.nextInt();
        int[] x = in.nextInts(n);
        Arrays.sort(x);


        long[][][] dp = new long[2][n+1][2501];
        dp[0][0][0] = 1;
        int psum = 0;
        for (int i = 0; i < n ; i++) {
            int fr = i % 2;
            int to = 1 - fr;
            for (int j = 0; j <= n; j++) {
                Arrays.fill(dp[to][j], 0);
            }

            for (int picked = 0; picked < n ; picked++) {
                for (int sum = 0; sum <= psum ; sum++) {
                    if (dp[fr][picked][sum] == 0) {
                        continue;
                    }
                    long base = dp[fr][picked][sum];
                    if (sum+x[i] <= 2500) {
                        int tp = picked+1;
                        int ts = sum+x[i];
                        dp[to][tp][ts] += base;
                    }
                    dp[to][picked][sum] += base;
                }
            }
            psum += x[i];
        }

        long total = 0;
        for (int i = 1 ; i <= n; i++) {
            if (i * a <= 2500) {
                total += dp[n%2][i][i*a];
            }
        }

        out.println(total);
        out.flush();
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int[] nextInts(int n) {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }


        private int[][] nextIntTable(int n, int m) {
            int[][] ret = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ret[i][j] = nextInt();
                }
            }
            return ret;
        }

        private long[] nextLongs(int n) {
            long[] ret = new long[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextLong();
            }
            return ret;
        }

        private long[][] nextLongTable(int n, int m) {
            long[][] ret = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ret[i][j] = nextLong();
                }
            }
            return ret;
        }

        private double[] nextDoubles(int n) {
            double[] ret = new double[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextDouble();
            }
            return ret;
        }

        private int next() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            if ('a' <= c && c <= 'z') {
                return (char) c;
            }
            if ('A' <= c && c <= 'Z') {
                return (char) c;
            }
            throw new InputMismatchException();
        }

        public String nextToken() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c-'0';
                c = next();
            } while (!isSpaceChar(c));
            return res*sgn;
        }

        public long nextLong() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c-'0';
                c = next();
            } while (!isSpaceChar(c));
            return res*sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}

Submission Info

Submission Time
Task C - Tak and Cards
User hamadu
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 6102 Byte
Status AC
Exec Time 207 ms
Memory 11244 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 100 / 100
Status
AC × 4
AC × 12
AC × 24
Set Name Test Cases
Sample example_01.txt, example_02.txt, example_03.txt, example_04.txt
Subtask1 example_01.txt, example_02.txt, example_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt
All example_01.txt, example_02.txt, example_03.txt, example_04.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt
Case Name Status Exec Time Memory
example_01.txt AC 147 ms 8144 KB
example_02.txt AC 147 ms 8020 KB
example_03.txt AC 167 ms 8404 KB
example_04.txt AC 163 ms 9552 KB
subtask1_01.txt AC 159 ms 9040 KB
subtask1_02.txt AC 171 ms 9172 KB
subtask1_03.txt AC 169 ms 9168 KB
subtask1_04.txt AC 164 ms 8788 KB
subtask1_05.txt AC 159 ms 8788 KB
subtask1_06.txt AC 152 ms 8020 KB
subtask1_07.txt AC 155 ms 8020 KB
subtask1_08.txt AC 159 ms 8916 KB
subtask1_09.txt AC 175 ms 8788 KB
subtask2_01.txt AC 199 ms 11000 KB
subtask2_02.txt AC 195 ms 11056 KB
subtask2_03.txt AC 191 ms 10928 KB
subtask2_04.txt AC 207 ms 11244 KB
subtask2_05.txt AC 199 ms 11160 KB
subtask2_06.txt AC 177 ms 10444 KB
subtask2_07.txt AC 187 ms 10960 KB
subtask2_08.txt AC 184 ms 10064 KB
subtask2_09.txt AC 183 ms 9940 KB
subtask2_10.txt AC 191 ms 10576 KB
subtask2_11.txt AC 191 ms 10580 KB