记录编号 570238 评测结果 AAAAAAAAAA
题目名称 [NOI Online 2021 1st] 积木小赛 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.564 s
提交时间 2022-03-25 19:25:09 内存使用 0.00 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#define OPEN(_x) freopen(#_x".in", "r", stdin); freopen(#_x".out", "w", stdout)
#define MAX(_a, _b) [&](int __a, int __b) { return __a < __b ? __b : __a; }((_a), (_b))
#define MIN(_a, _b) [&](int __a, int __b) { return __a > __b ? __b : __a; }((_a), (_b))
#define fi first
#define se second

using ll = long long;
using ull = unsigned long long;
using PII = std::pair<int, int>;
namespace IO {
    template <typename T> inline T read() {
        char ch = getchar();
        T ret = 0, sig = 1;
        while(ch < '0' || ch > '9') { if(ch == '-') sig = -1; ch = getchar(); }
        while(ch >= '0' && ch <= '9') ret *= 10, ret += ch - 48, ch = getchar();
        return ret * sig;
    }
    template <typename T> inline void write(T out) {
		if(!out) { putchar('0'); return; }
        int stk[100], tt = 0;
        if(out < 0) out = -out, putchar('-');
        while(out) stk[tt++] = out % 10, out /= 10;
        for(register int i = --tt; i>=0; --i) putchar(stk[i] + 48);
        putchar(' ');
    }
    template <typename T> inline void read(T& ret) { ret = IO::read<T>(); }
    template <typename T, typename... Args> inline void read(T& x, Args&... args) { IO::read(x), IO::read(args...); }
    template <typename T, typename... Args> inline void write(T x, Args... args)  { IO::write(x), IO::write(args...); }
};


const int N = 3010, P = 13331;
int n;
char a[N], b[N];
std::set<ull> res;

int main() {
    OPEN(noi_online2021_block);
    scanf("%d %s %s", &n, a + 1, b + 1);
    for (register int i = 1; i<=n; ++i) {
        ull x = 0; int k = 1;
        for (register int j = i; i<=n; ++j) {
            while (k <= n && a[k] != b[j]) ++k;
            if (k > n) break;
            ++k;
            x = x * P + b[j] - 'a' + 1;
            res.insert(x);
        }
    }
    printf("%lld", res.size());
    return 0;
}