QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607255#7814. 消消乐tiankonguse60 103ms15444kbC++202.3kb2024-10-03 14:29:192024-10-03 14:29:20

Judging History

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

  • [2024-10-03 14:29:20]
  • 评测
  • 测评结果:60
  • 用时:103ms
  • 内存:15444kb
  • [2024-10-03 14:29:19]
  • 提交

answer

/*
ID: tiankonguse
TASK: game
LANG: C++
CONTEST: CSP-S 2023
OJ: https://qoj.ac/problem/7814
*/
#define TASK "game"

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int mod1e7 = 1000000007, mod1e9 = 1000000009;
const ll BASE = 29;

const int N = 2000010;
const int M = 26;
char str[N];
void InitIO() {
  // #ifndef USACO_LOCAL_JUDGE
  //   freopen(TASK ".in", "r", stdin);
  //   freopen(TASK ".out", "w", stdout);
  // #endif
}

ll qpow(ll x, ll v, ll mod) {
  x = x % mod;
  ll y = 1;
  while (v) {
    if (v & 1) y = y * x % mod;
    x = x * x % mod;
    v >>= 1;
  }
  return y;
}
ll inv(ll x, ll mod) { return qpow(x, mod - 2, mod); }
const int NN = 1000;
const int MM = 100;
bool is[NN];
int prm[MM];
int getprm() {
  int e = (int)(sqrt(0.0 + N) + 1), k = 0, i;
  memset(is, 1, sizeof(is));
  prm[k++] = 2;
  is[0] = is[1] = 0;
  for (i = 4; i < NN; i += 2) is[i] = 0;
  for (i = 3; i < e; i += 2) {
    if (is[i]) {
      prm[k++] = i;
      for (int s = i + i, j = i * i; j < NN; j += s) is[j] = 0;
    }
  }
  for (; i < NN; i += 2)
    if (is[i]) prm[k++] = i;
  return k;
}

/*

*/

void Solver() {
  vector<ll> X7(26);
  vector<ll> X9(26);
  vector<ll> RX7(26);
  vector<ll> RX9(26);

  int K = getprm();
  for (int i = 0; i < 26; i++) {
    K--;
    X7[i] = prm[K];
    RX7[i] = inv(X7[i], mod1e7);
    // printf("i=%d X7=%lld RX7=%lld *=%lld\n", i, X7[i], RX7[i],
    //        (X7[i] * RX7[i]) % mod1e7);

    K--;
    X9[i] = prm[K];
    RX9[i] = inv(X9[i], mod1e9);
    // printf("i=%d X9=%lld RX9=%lld *=%lld\n", i, X9[i], RX9[i],
    //        (X9[i] * RX9[i]) % mod1e9);
  }

  ll n;
  scanf("%lld%s", &n, str);
  unordered_map<ll, ll> h;

  stack<char> sta;
  ll pre7 = 1;
  ll pre9 = 1;
  ll ans = 0;
  h[pre7 * mod1e9 + pre9] = 1;
  for (int i = 0; i < n; i++) {
    const char c = str[i];
    const ll v = c - 'a';

    if (i & 1) {
      pre7 = (pre7 * X7[v]) % mod1e7;
      pre9 = (pre9 * X9[v]) % mod1e9;
    } else {
      pre7 = (pre7 * RX7[v]) % mod1e7;
      pre9 = (pre9 * RX9[v]) % mod1e9;
    }
    // printf("i=%d add+%lld\n", i, h[pre]);
    ll pre = pre7 * mod1e9 + pre9;
    ans += h[pre];
    h[pre]++;
  }

  printf("%lld\n", ans);
}

int main() {
  InitIO();
  Solver();
  return 0;
}
/*
8
accabccb

*/

详细


Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 0ms
memory: 4096kb

input:

10
aaaaaaaaaa

output:

25

result:

ok single line: '25'

Test #2:

score: 5
Accepted
time: 1ms
memory: 3784kb

input:

10
ooooppuuhh

output:

16

result:

ok single line: '16'

Test #3:

score: 5
Accepted
time: 1ms
memory: 3804kb

input:

10
nnppkkppjj

output:

16

result:

ok single line: '16'

Test #4:

score: 5
Accepted
time: 1ms
memory: 3780kb

input:

10
vvcckkhhqq

output:

15

result:

ok single line: '15'

Test #5:

score: 5
Accepted
time: 1ms
memory: 3804kb

input:

10
llmmxxoopp

output:

15

result:

ok single line: '15'

Test #6:

score: 5
Accepted
time: 1ms
memory: 3816kb

input:

800
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjddzziiyyyyjjooppiivvppmmooppttnnbbmmaaqqvvkkllyyvvmmjjsswwxxccwweeeekkhhaakkvvffaaiieessmmiibbff...

output:

38306

result:

ok single line: '38306'

Test #7:

score: 5
Accepted
time: 1ms
memory: 4112kb

input:

800
pffpgppguqqugllgwhhwxjjxpkkpxnnxlkklunnuxiixallayqqyccccjnnjnyynqccqqjjqtuutboobwddwfwwfgvvgwuuwpqqppttpyggysrrsgwwgeddexbbxbssbvbbvbeebweewwkkwwddwnoontddtcddcajjapffptcctkeekboobfjjfvaavpjjpriirlfflnazdsevmozgezlngnhktrllcgorjoollwtqylmmzxfeibnifcebsnnugzluzlizievzxfnlokzodymigextlmyltzbmptyjf...

output:

27479

result:

ok single line: '27479'

Test #8:

score: 5
Accepted
time: 0ms
memory: 3900kb

input:

8000
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

3820477

result:

ok single line: '3820477'

Test #9:

score: 5
Accepted
time: 1ms
memory: 3908kb

input:

8000
neenbnnbvjjvddddommolrrlzttzqwwqlfflijjiaqqayaayihhiqmmqduudlzzlyzzyannatyytfiifbqqbroorcffcgjjgwhhwoqqopuupdjjdeqqewnnwvwwvpiiprqqrukkuhbbhsiisrqqrxvvxfmmfzkkzjlljimmiazzariirdvvdcuucpaapbaabbaabccccxqqxivvipttpqffqmggmzhhzdaadyxxyhccheddeaiianggnxjjxqssqfaafqllqskksfuufviivozzocwwcznnzfxxfnss...

output:

2713693

result:

ok single line: '2713693'

Test #10:

score: 5
Accepted
time: 1ms
memory: 3980kb

input:

8000
ivviurrukrrkaccafoofaxxaleelcyycsiisimmifvvfoeeodppdneenqjjqsccsguugonnoyiiymttmcjjcmkkmjwwjieeikeekdbbdolloyvvyolloxiixmaamfnnfzrrzqbbqweewvttvboobbeebcmmcsqqsiyyifddfyvvyvttvvddvejjeeeeeleellzzlzbbzcrrcobbowsswquuqozzoyqqyulluwvvwyxxyxllxwrrwgmmgeppecvvcsiisyvvyukkuyppyryyrhjjhthhtvssvvnnvnee...

output:

2721590

result:

ok single line: '2721590'

Test #11:

score: 0
Wrong Answer
time: 64ms
memory: 12756kb

input:

200000
tdaatgfvypbdkxdlvttiuksoooxszoqnqvmtznizlqfstlenqrnmdpkmvhmzftporwzvlbpyplrvrkgrpvqxyjcwwpcinilarbaudodadcglszflkzvmmdahgqphqoueltddqlymwpvweslymviccsmhuezesmlwsswgznaofullpxciuezrbkxfnodiglhpyrfcjajyuqzfoxsysgeqrqmvtqysypgaivfetwhmgxngzdvavbkipanoopqftdmntwpxgaljiqrkppywfuspzfgljheckapftjqar...

output:

8367

result:

wrong answer 1st lines differ - expected: '8356', found: '8367'

Test #12:

score: 0
Wrong Answer
time: 62ms
memory: 12764kb

input:

200000
nleqrvpkpopfbstnolidsxrfhivbwbbqbwxmvymzmnwozrbklbuwliccquzhpfjsbxlnkzewvjpjarqmwcpsvovxeynjrgdjxrauincbnjvokawliinjqqulwxxeztpbrotihuiyjjqsxxosragocxbpjmhquczgwfakfaojxslteazikjqkebpcrrggswjiyetkpyvjubhtoounhveftykvetuwqgpddicnarbsigpjytmhcymvapbmkforkaeccsuhmwiuljmvajlztzjghnohlmxnmdehfxnra...

output:

8356

result:

wrong answer 1st lines differ - expected: '8340', found: '8356'

Test #13:

score: 5
Accepted
time: 4ms
memory: 4040kb

input:

200000
abbabbbbbbaababaaabaaaababaaaaaabbababababbabbaaababbbbaabaabbbbbbababaabababbababaabbaabaaaabbbbbaabbbbaababbbabaaababbbbbbbbbbabbbabaabaabaababbbbbbabaabbbbbbbbbbaaabbbbabaabbaababaaabbabbaaabbbbbaaabababaababbaaabbbbababbbbbbaaaabaaaaaaabbbaabbaaaabbabbbbbaabbbbbbbabbaaaabaaabaabbaaaababbb...

output:

52315097

result:

ok single line: '52315097'

Test #14:

score: 5
Accepted
time: 5ms
memory: 4284kb

input:

200000
aaaababaaaaabbabababbbbabbbbababbabbaabaaabbabbaabaaaaaabaaaabbbbbbbabaabbabaabababbbaabbbbabbbbbaabaaaabaaaababaaaabbaaaaabbbabbbabbbbbbbaabbbabbaaabbbabaabaaaaaaaaababbaaabbbbaabaabbaaababbabbaabbbbaaababbbbbbbbbbbaabaaabbaaabaabbaaabbabaabbabbaabbbababbaaabaaaaaabbbbbbbabaabbabbaabaabaabaa...

output:

72221142

result:

ok single line: '72221142'

Test #15:

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

input:

200000
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

2395581638

result:

wrong answer 1st lines differ - expected: '2395581278', found: '2395581638'

Test #16:

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

input:

200000
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

2396625627

result:

wrong answer 1st lines differ - expected: '2396621459', found: '2396625627'

Test #17:

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

input:

200000
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...

output:

2395864521

result:

wrong answer 1st lines differ - expected: '2395864064', found: '2395864521'

Test #18:

score: 0
Wrong Answer
time: 95ms
memory: 15236kb

input:

2000000
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...

output:

239587350429

result:

wrong answer 1st lines differ - expected: '239586659381', found: '239587350429'

Test #19:

score: 0
Wrong Answer
time: 94ms
memory: 15332kb

input:

2000000
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

239687549007

result:

wrong answer 1st lines differ - expected: '239687303822', found: '239687549007'

Test #20:

score: 0
Wrong Answer
time: 103ms
memory: 15444kb

input:

2000000
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

239609210194

result:

wrong answer 1st lines differ - expected: '239608981171', found: '239609210194'