Submission #74696728


Source Code Expand

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

@SuppressWarnings("DuplicatedCode")
public class Main {
    static int MAX_STRING_LENGTH = (int) 1e6; // 字符串最大长度
    static int MAX_DIGIT_LENGTH = (int) 1e6; // 数位最大长度
    static int MOD7 = (int) 1e9 + 7, MOD8 = 80112002, MOD9 = 998244353, inf = Integer.MAX_VALUE;

    /***** 检查 T *****/
    static class Solution {

        void solve() {
            char[] s = io.nextCharArray(true), t = io.nextCharArray(true);
            int n = s.length, m = t.length;
            long ans = (long) n * (n + 1) / 2;
            int[][] f = new int[n + 1][m + 1];
            f[0][0] = 1;
            for (int i = 0; i < n; i++) {
                f[i + 1][0] = i + 2;
                for (int j = 0; j < m; j++) {
                    f[i + 1][j + 1] = s[i] == t[j] ? f[i][j] : f[i][j + 1];
                }
                ans -= f[i + 1][m];
            }
            io.println(ans);
        }


    }


    public static void main(String[] args) {
        io = new IO();
        int T = 1;
        // T = io.nextInt();
        for (; T > 0; T--) {
            new Solution().solve();
        }
        io.close();
    }

    static IO io;
    static class IO {
        BufferedInputStream bis = new BufferedInputStream(System.in);
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));

        int nextInt() {
            return (int) nextLong();
        }

        long nextLong() {
            try {
                long sign = 1, x = 0;
                int c = bis.read();
                while (c < '0' || c > '9') {
                    if (c == '-') sign = -1;
                    c = bis.read();
                }
                while (c >= '0' && c <= '9') {
                    x = x * 10 + (c - '0');
                    c = bis.read();
                }
                return sign * x;
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                try {
                    int sign = 1, x = 0;
                    int c = bis.read();
                    while (c < '0' || c > '9') {
                        if (c == '-') sign = -1;
                        c = bis.read();
                    }
                    while (c >= '0' && c <= '9') {
                        x = x * 10 + (c - '0');
                        c = bis.read();
                    }
                    a[i] = sign * x;
                } catch (IOException e) {
                    throw new RuntimeException(e.getMessage());
                }
            }
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                try {
                    long sign = 1, x = 0;
                    int c = bis.read();
                    while (c < '0' || c > '9') {
                        if (c == '-') sign = -1;
                        c = bis.read();
                    }
                    while (c >= '0' && c <= '9') {
                        x = x * 10 + (c - '0');
                        c = bis.read();
                    }
                    a[i] = sign * x;
                } catch (IOException e) {
                    throw new RuntimeException(e.getMessage());
                }
            }
            return a;
        }

        int[] nextDigitArray(int n) {
            try {
                int[] a = new int[n];
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                int i = 0;
                while (!ignore(x)) {
                    a[i++] = x - '0';
                    x = bis.read();
                }
                return a;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        private int[] DIGIT_ARRAY;

        int[] nextDigitArray() {
            try {
                if (DIGIT_ARRAY == null) {
                    DIGIT_ARRAY = new int[MAX_DIGIT_LENGTH];
                }
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                int m = 0;
                while (!ignore(x)) {
                    DIGIT_ARRAY[m++] = x - '0';
                    x = bis.read();
                }
                int[] a = new int[m];
                System.arraycopy(DIGIT_ARRAY, 0, a, 0, m);
                return a;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        char nextChar() {
            try {
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                return (char) x;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        String[] nextStringArray(int n) {
            String[] a = new String[n];
            for (int i = 0; i < n; i++) {
                try {
                    if (CHAR_ARRAY == null) {
                        CHAR_ARRAY = new char[MAX_STRING_LENGTH];
                    }
                    int x = bis.read();
                    while (ignore(x)) {
                        x = bis.read();
                    }
                    int m = 0;
                    while (x != ' ' && x != ',' && !ignore(x)) {
                        CHAR_ARRAY[m++] = (char) x;
                        x = bis.read();
                    }
                    a[i] = new String(CHAR_ARRAY, 0, m);
                } catch (IOException e) {
                    throw new RuntimeException(e.getMessage());
                }
            }
            return a;
        }

        private char[] CHAR_ARRAY;

        char[] nextCharArray(boolean line) {
            try {
                if (CHAR_ARRAY == null) {
                    CHAR_ARRAY = new char[MAX_STRING_LENGTH];
                }
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                int m = 0;
                while (line ? (x == ' ' || x == ',' || !ignore(x)) : !ignore(x)) {
                    CHAR_ARRAY[m++] = (char) x;
                    x = bis.read();
                }
                char[] a = new char[m];
                System.arraycopy(CHAR_ARRAY, 0, a, 0, m);
                return a;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        char[] nextCharArray(int n) {
            try {
                char[] a = new char[n];
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                int i = 0;
                while (!ignore(x)) {
                    a[i++] = (char) x;
                    x = bis.read();
                }
                return a;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

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

        String nextString(boolean line) {
            return new String(nextCharArray(line));
        }

        String nextString() {
            return nextString(false);
        }

        boolean nextBoolean() {
            return "true".equalsIgnoreCase(nextString());
        }

        double nextDouble() {
            return Double.parseDouble(nextString());
        }

        void println(Object obj) {
            print(obj);
            print("\n");
        }

        void println() {
            print('\n');
        }

        void print(Object obj) {
            pw.print(obj);
        }

        void printf(String format, Object... obj) {
            pw.printf(format, obj);
        }

        void close() {
            try {
                if (bis != null) bis.close();
                if (pw != null) {
                    pw.flush();
                    pw.close();
                }
                bis = null;
                pw = null;
            } catch (Exception ignore) {
            }
        }
    }
}

Submission Info

Submission Time
Task D - No-Subsequence Substring
User gaoyuliang
Language Java24 (OpenJDK 24.0.2)
Score 400
Code Size 8828 Byte
Status AC
Exec Time 122 ms
Memory 90832 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 56
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 45 ms 39792 KiB
00_sample_01.txt AC 39 ms 39952 KiB
00_sample_02.txt AC 39 ms 40240 KiB
01_random_03.txt AC 88 ms 72064 KiB
01_random_04.txt AC 94 ms 72276 KiB
01_random_05.txt AC 76 ms 50004 KiB
01_random_06.txt AC 72 ms 54256 KiB
01_random_07.txt AC 73 ms 52332 KiB
01_random_08.txt AC 91 ms 72192 KiB
01_random_09.txt AC 108 ms 90788 KiB
01_random_10.txt AC 103 ms 72120 KiB
01_random_11.txt AC 115 ms 90520 KiB
01_random_12.txt AC 76 ms 50432 KiB
01_random_13.txt AC 74 ms 52304 KiB
01_random_14.txt AC 97 ms 72092 KiB
01_random_15.txt AC 101 ms 90192 KiB
01_random_16.txt AC 113 ms 90816 KiB
01_random_17.txt AC 96 ms 72156 KiB
01_random_18.txt AC 87 ms 52240 KiB
01_random_19.txt AC 114 ms 90632 KiB
01_random_20.txt AC 94 ms 72144 KiB
01_random_21.txt AC 89 ms 53796 KiB
01_random_22.txt AC 113 ms 90552 KiB
01_random_23.txt AC 122 ms 90620 KiB
01_random_24.txt AC 114 ms 90528 KiB
01_random_25.txt AC 121 ms 90832 KiB
01_random_26.txt AC 96 ms 72240 KiB
01_random_27.txt AC 94 ms 71972 KiB
01_random_28.txt AC 111 ms 90472 KiB
01_random_29.txt AC 104 ms 72232 KiB
01_random_30.txt AC 93 ms 72152 KiB
01_random_31.txt AC 98 ms 72372 KiB
01_random_32.txt AC 70 ms 48424 KiB
01_random_33.txt AC 115 ms 90672 KiB
01_random_34.txt AC 95 ms 72028 KiB
01_random_35.txt AC 114 ms 90796 KiB
01_random_36.txt AC 108 ms 90668 KiB
01_random_37.txt AC 101 ms 72256 KiB
01_random_38.txt AC 93 ms 72084 KiB
01_random_39.txt AC 102 ms 72072 KiB
01_random_40.txt AC 96 ms 72364 KiB
01_random_41.txt AC 105 ms 90444 KiB
01_random_42.txt AC 103 ms 90804 KiB
01_random_43.txt AC 74 ms 47564 KiB
01_random_44.txt AC 90 ms 72200 KiB
01_random_45.txt AC 74 ms 47732 KiB
01_random_46.txt AC 109 ms 90648 KiB
01_random_47.txt AC 84 ms 71952 KiB
01_random_48.txt AC 65 ms 43116 KiB
01_random_49.txt AC 83 ms 71996 KiB
01_random_50.txt AC 79 ms 57680 KiB
01_random_51.txt AC 106 ms 90640 KiB
01_random_52.txt AC 79 ms 47012 KiB
01_random_53.txt AC 40 ms 40200 KiB
01_random_54.txt AC 38 ms 40260 KiB
01_random_55.txt AC 38 ms 39912 KiB