Submission #70224440


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fix(x) fixed << setprecision(x)
#define rep(i, start, end) for (auto i = (start); (i) < (end); (i)++)
#define repe(i, start, end) for (auto i = (start); (i) <= (end); (i)++)
#define rrep(i, start, end) for (auto i = (start); (i) >= (end); (i)--)

constexpr auto PI = 3.14159265358979;
constexpr int INF = 1e+9;
constexpr long long INFL = 1e+18;

using ll = long long;
using lld = long double;
// using mint = modint1000000007;
using mint = modint998244353;
using Pair_int = pair<int, int>;
using Pair_ll = pair<ll, ll>;
template <class T>
using Graph = vector<vector<T>>;

template <class T1, class T2>
inline auto div_floor(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a >= 0)
        return a / b;
    else
        return (a + 1) / b - 1;
}
template <class T1, class T2>
inline auto div_ceil(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a <= 0)
        return a / b;
    else
        return (a - 1) / b + 1;
}
ll pow_int(ll x, ll n)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}
ll pow_mod(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll gcd(ll x, ll y)
{
    if (x < y)
        swap(x, y);
    ll r;
    while (y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
ll lcm(ll x, ll y) { return ll(x / gcd(x, y)) * y; }
ll nCk(ll n, ll r)
{
    if (r < 0 || n < r)
        return 0;
    ll ans = 1;
    for (ll i = 1; i <= r; i++)
    {
        ans *= n--;
        ans /= i;
    }
    return ans;
}
int get_rand(int seed, int min, int max)
{
    static mt19937_64 mt64(seed);
    uniform_int_distribution<int> get_rand_int(min, max);
    return get_rand_int(mt64);
}
template <typename T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <typename T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
template <class T1, class T2>
inline auto mod(T1 x, T2 r) { return (x % r + r) % r; }

// ======================================== //

int main()
{
    int N, K;
    string S;
    cin >> N >> K >> S;

    map<string, int> mp;
    for (int i = 0; i <= N - K; i++)
    {
        mp[S.substr(i, K)]++;
    }

    int ans = 0;
    for (const auto &[key, value] : mp)
    {
        chmax(ans, value);
    }

    cout << ans << endl;

    for (const auto &[key, value] : mp)
    {
        if (value == ans)
        {
            cout << key << " ";
        }
    }
    cout << endl;

    return 0;
}

Submission Info

Submission Time
Task B - Most Frequent Substrings
User Yuulis
Language C++ 23 (gcc 12.2)
Score 200
Code Size 2877 Byte
Status AC
Exec Time 1 ms
Memory 3712 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 22
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 3516 KiB
00-sample-02.txt AC 1 ms 3512 KiB
00-sample-03.txt AC 1 ms 3704 KiB
01-01.txt AC 1 ms 3516 KiB
01-02.txt AC 1 ms 3504 KiB
01-03.txt AC 1 ms 3520 KiB
01-04.txt AC 1 ms 3512 KiB
01-05.txt AC 1 ms 3516 KiB
01-06.txt AC 1 ms 3612 KiB
01-07.txt AC 1 ms 3576 KiB
01-08.txt AC 1 ms 3580 KiB
01-09.txt AC 1 ms 3528 KiB
01-10.txt AC 1 ms 3580 KiB
01-11.txt AC 1 ms 3576 KiB
01-12.txt AC 1 ms 3556 KiB
01-13.txt AC 1 ms 3424 KiB
01-14.txt AC 1 ms 3420 KiB
01-15.txt AC 1 ms 3712 KiB
01-16.txt AC 1 ms 3496 KiB
01-17.txt AC 1 ms 3480 KiB
01-18.txt AC 1 ms 3620 KiB
01-19.txt AC 1 ms 3528 KiB