QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#685857#526. MagicMher7770 232ms156472kbC++205.5kb2024-10-28 21:39:452024-10-28 21:39:45

Judging History

你现在查看的是最新测评结果

  • [2024-10-28 21:39:45]
  • 评测
  • 测评结果:0
  • 用时:232ms
  • 内存:156472kb
  • [2024-10-28 21:39:45]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <cassert>
#include <fstream>
using namespace std;
mt19937 rnd(time(nullptr));

/* -------------------- Typedefs -------------------- */

typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef float fl;
typedef long double ld;

/* -------------------- Usings -------------------- */

using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* -------------------- Defines -------------------- */

#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define all(x) (x).begin(), (x).end()
#define USACO freopen("feast.in", "r", stdin); freopen("feast.out", "w", stdout);

/* -------------------- Constants -------------------- */

const int dx[8] = { -1, 0, 1, 0, -1, -1, 1, 1 };
const int dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int MAX = int(1e9 + 5);
const ll MAXL = ll(1e18) + 5ll;
const ll MOD = ll(1000000007);
const ll MOD2 = ll(998244353);

/* -------------------- Functions -------------------- */

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void precision(int x) {
    cout.setf(ios::fixed | ios::showpoint);
    cout.precision(x);
}

ll gcd(ll a, ll b) {
    if (a == 0 || b == 0) return(max(a, b));
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

ll range_sum(ll a, ll b) {
    if (a > b) return 0ll;
    ll dif = a - 1, cnt = b - a + 1;
    ll ans = ((b - a + 1) * (b - a + 2)) / 2;
    ans += ((b - a + 1) * dif);
    return ans;
}

string dec_to_bin(ll a) {
    string s = "";
    for (ll i = a; i > 0; ) {
        ll k = i % 2;
        i /= 2;
        char c = k + 48;
        s += c;
    }
    if (a == 0) {
        s = "0";
    }
    reverse(all(s));
    return s;
}

ll bin_to_dec(string s) {
    ll num = 0;
    for (int i = 0; i < s.size(); i++) {
        num *= 2ll;
        num += (s[i] - '0');
    }
    return num;
}

ll factorial_by_mod(ll n, ll mod) {
    ll ans = 1;
    ll num;
    for (ll i = 1; i <= n; ++i) {
        num = i % mod;
        ans *= num;
        ans %= mod;
    }
    return ans;
}

bool isPrime(ll a) {
    if (a == 1) return false;
    for (ll i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}

ll binpow(ll a, ll b) {
    if (!a) return 0;
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
        }
        b >>= 1;
        a *= a;
    }
    return ans;
}

ll binpow_by_mod(ll a, ll b, ll mod) {
    if (!a) return 0;
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
            ans %= mod;
        }
        b >>= 1;
        a *= a;
        a %= mod;
    }
    return ans;
}

/* -------------------- Solution -------------------- */

const int N = 100005, M = 55;
ll dp[N], p_pow[N], nxt[N][M];
vi a[M][M];
int m;

void slv() {
    int n;
    string s;
    cin >> n >> s;
    map<char, int> mp;
    vector<char> v;
    for (int i = 0; i < n; ++i) {
        if (mp[s[i]]) continue;
        mp[s[i]] = ++m;
        v.pub(s[i]);
    }
    for (int i = 0; i < m; ++i) {
        int ind1 = mp[v[i]];
        for (int j = 0; j < m; ++j) {
            if (i == j) continue;
            int ind2 = mp[v[j]];
            a[ind1][ind2].assign(n + 1, 0);
            for (int ind = 1; ind <= n; ++ind) {
                a[ind1][ind2][ind] = a[ind1][ind2][ind - 1];
                if (s[ind - 1] == v[i]) {
                    ++a[ind1][ind2][ind];
                }
                else if (s[ind - 1] == v[j]) {
                    --a[ind1][ind2][ind];
                }
            }
        }
    }
    ll p = 31;
    p_pow[0] = 1ll;
    for (int i = 1; i <= m; ++i) {
        p_pow[i] = (p_pow[i - 1] * p) % MOD;
    }
    for (int i = 1; i <= m; ++i) {
        vll v(n + 1, 0);
        int cur = 0;
        for (int ind = 0; ind <= n; ++ind) {
            cur = 0;
            for (int j = 1; j <= m; ++j) {
                if (i == j) continue;
                v[ind] += a[i][j][ind] * p_pow[cur];
                v[ind] %= MOD;
                ++cur;
            }
        }
        unordered_map<ll, int> last;
        for (int ind = n; ind >= 0; --ind) {
            nxt[i][ind] = last[v[ind]];
            last[v[ind]] = ind;
        }
    }
    ll ans = 0;
    for (int i = n; i >= 1; --i) {
        int ind = mp[s[i - 1]];
        int r = nxt[ind][i - 1];
        if (!r) continue;
        dp[i] = dp[r + 1] + 1ll;
        dp[i] %= MOD;
        ans += dp[i];
        ans %= MOD;
    }
    cout << ans;
}

void cs() {
    int tstc = 1;
    //cin >> tstc;
    while (tstc--) {
        slv();
    }
}

void precalc() {
    return;
}

int main() {
    fastio();
    precalc();
    //precision(0);
    cs();
    return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5784kb

input:

100
SsSsSsSsSsSSssSSsSSssSsSsssssSsSssssSsSSSSsSSSSsSsSssSSSSsSSsssSssSssssSsssSssSsSssssssSSssSSsSSSsSS

output:

383

result:

wrong answer 1st lines differ - expected: '440', found: '383'

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 4796kb

input:

100
XUHzGCBgfsEvaJiOlmjuNwYTcpkPynZtVASQqhMDoeFRKbdLIrgOGBUlECmJHzisvfXaQecMypSjPqRtTDowkZnFNYVAuhUrXosy

output:

6

result:

wrong answer 1st lines differ - expected: '3', found: '6'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 5732kb

input:

200
xtIxtIxtIxtIxxttxIxxxtIItxIIIxxItItxtIItxIxxtIItxIxIIxItttItxxtItxItxItxItxxIIIxtxtIxxtIIttIItIxIItIxtIxtIxtIxtIxttttxIttxtxIxxtIIxtxIIxIIxxIIttIIIxtxIttxItxxxxItxItxItxItxItxItxtxxtIxttIxIIIItxtIxtIx

output:

232

result:

wrong answer 1st lines differ - expected: '402', found: '232'

Test #4:

score: 0
Wrong Answer
time: 5ms
memory: 7776kb

input:

500
mhUMlYtJLIiOkfsBSTodgrDQZWbCnvlJLMhmYItUivdnMgDmUCblrfhTsWoQkOSZBYtDrvbniIhUMmdfLsJgTlCvJLSQlnLZMiDIfQYZSgkTJsbWoOodrBOWCkBtnnmYlDLhTmMSbilsJIUvtUQhdgrvfCLYvkWCYhodtfBgsmJObiDroMkZZQtOSTIIWUBiQbLrDhsgWklCtfoCvMlSdUnmJdhLnTvYYWfUZDbSJgIkZOJminfrZsiBMbODgMoQsQTIlSToLlLmDYtvSLiBMdbBgOmUUJTQdfkvlCWn...

output:

70

result:

wrong answer 1st lines differ - expected: '19', found: '70'

Test #5:

score: 0
Wrong Answer
time: 1ms
memory: 6212kb

input:

1000
yzdBsSvHpkyzdBsSvHpkyzdBsSvHpkyzdBsSvHpkyzdBsSvHpkyzdBsSvHpkyzdBsSvHpkyzdBsSvHpkyzdBsSvHpkyzdBsSvHpkpkkkHsHSBsdsvkyyzzSBykpHzskdpvSyBHszkdpvSyBHszkdpvSyBHszkdpvSyBHszkdpvSyBHszkdpvSyBHszpsBpyzdsyHkpyvzzzszkpyyBzySHzkSdvyBspHzkSdvyBspHzkSdvyBspHzkSdvyBspHzkSdvyBspHvpkkSsszddykHzkpzBpBkdHSvszypBk...

output:

1204

result:

wrong answer 1st lines differ - expected: '3103', found: '1204'

Test #6:

score: 0
Wrong Answer
time: 36ms
memory: 25140kb

input:

2000
MyWnObAVvNzcYqECPmTtJXpwjeIkLixhHKlRguQBsDrdSGaUFZWbnMyAOvVunpeHyhNYczPmCFjLKsEwROxMUWSJtrlgIkqQdTiBGDXaZrjClWIEVxwdibQLntNMKPmvqOYFUzuTepsghJkHASRcyDaLVdiWjMCbrEQNXBnxZGKwlItBHhAFcRpuzzEvGbyNZYvgqVTsTmeqAPkmXDacSYUCJPOZRJinjuxSHsUhraXgBDMFplQtWIwkdeGLyOKVFnbPzchHNYepuyCvAmCLDkZcZkidejaqvumJbVL...

output:

177

result:

wrong answer 1st lines differ - expected: '56', found: '177'

Test #7:

score: 0
Wrong Answer
time: 1ms
memory: 7836kb

input:

2000
WRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRRRWWWRRWWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRWRW...

output:

50471

result:

wrong answer 1st lines differ - expected: '207783', found: '50471'

Test #8:

score: 0
Wrong Answer
time: 1ms
memory: 5908kb

input:

5000
BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

264814

result:

wrong answer 1st lines differ - expected: '666340', found: '264814'

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 6316kb

input:

20000
umumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumumum...

output:

4068669

result:

wrong answer 1st lines differ - expected: '19154645', found: '4068669'

Test #10:

score: 0
Wrong Answer
time: 3ms
memory: 7056kb

input:

50000
mpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmpmp...

output:

26746294

result:

wrong answer 1st lines differ - expected: '86508692', found: '26746294'

Test #11:

score: 0
Wrong Answer
time: 3ms
memory: 10352kb

input:

100000
ElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElE...

output:

123661799

result:

wrong answer 1st lines differ - expected: '513536001', found: '123661799'

Test #12:

score: 0
Wrong Answer
time: 6ms
memory: 6816kb

input:

100000
ElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElE...

output:

249875409

result:

wrong answer 1st lines differ - expected: '499749995', found: '249875409'

Test #13:

score: 0
Wrong Answer
time: 0ms
memory: 10156kb

input:

100000
ElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElElE...

output:

249875409

result:

wrong answer 1st lines differ - expected: '499749995', found: '249875409'

Test #14:

score: 0
Wrong Answer
time: 213ms
memory: 102128kb

input:

10000
IrUwTbhZexXAplmaVfqMOBigvjGHoCQJsYNFDLcnRdyESkPutzbiHhVwAsvZOgqMITmClxDQJpojfFeBaNGUYXrIcRXxSPkETAewrpZnbdyzLutUhvHsVxcCMFlNBoigJQOYDjGImafqXRjdeJrtChDgEdlyUhkvuaENsfLPQSoSAiZBOGZrPRcwYLqkzzTUImMnwHyutnVTbFbpvYymCpaaetgENRdXJgXuoxvNUDDxOVcjELfQGJfihHlqFCsljkIdshMeABrIHiTOgoQsRYVOxZqLoDpFTfSAYm...

output:

344

result:

wrong answer 1st lines differ - expected: '100', found: '344'

Test #15:

score: 0
Wrong Answer
time: 7ms
memory: 10792kb

input:

50000
RxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRxNHRx...

output:

6412306

result:

wrong answer 1st lines differ - expected: '25510755', found: '6412306'

Test #16:

score: 0
Wrong Answer
time: 50ms
memory: 45148kb

input:

100000
dFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFExBWcrYPdFE...

output:

4076145

result:

wrong answer 1st lines differ - expected: '39836830', found: '4076145'

Test #17:

score: 0
Time Limit Exceeded

input:

100000
mXYwpGNxavDJQIysKAeZibMOrkfWdlhcFuHnLTESCjUPqztoBgVRpYNXmwGxQDsJIeAyKavLpWTdjURhuEYbtngiHlfZCqBozFOrkVNMScPgKrEQDltaHdmvUFkXuZeILoWOszMiASTBnbjPchxyqfGwJCRXDapvwxQyYImJVGNYhMbNkdZjPgpuUmBKtfienWHwrOSACFEcqzoTXVLslRisvxbKQaDIeZAGyOJMmCTWzhDRwpLPBVdqJsGXEtUuljxrkFfSYHNcnogQKIayvdbWMlAZerOfkiUuE...

output:


result:


Test #18:

score: 0
Time Limit Exceeded

input:

100000
QeuiySpTEKbUdvBrjgIznkLhXRVoDwJAYGPONWfMFqlZHmCacstxwBzfWNMukAUDvrTEiXjbnYQGpPoVIKgeLRdhyJOSNczmZMwftxlHBCasFWqUdLAlpbcuTokyxturpIKEeiYbqSTXaORQZeDyimvQUsdhnCGJKvSPjEVHgFrBODGgWXNNhcMYoLPjIVJkAwRfznmmROpuTdyKYMETUtlbSdqvIBCCJDusqnUzZwhZbtecxQkapeLriHWlAoxafXsGyFQiMBXzOHVtJVNScnkflNgHLBPhGAuqo...

output:


result:


Test #19:

score: 0
Wrong Answer
time: 111ms
memory: 91396kb

input:

100000
gruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZWdVkONqQgruAhpZW...

output:

1934549

result:

wrong answer 1st lines differ - expected: '27619254', found: '1934549'

Test #20:

score: 0
Wrong Answer
time: 232ms
memory: 156472kb

input:

100000
MvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgutjQDXzoMvNUleIZJnpgu...

output:

1176192

result:

wrong answer 1st lines differ - expected: '21636849', found: '1176192'