QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608939#8340. 3 SumyangrunTL 3ms5048kbC++141.2kb2024-10-04 09:27:562024-10-04 09:27:57

Judging History

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

  • [2024-10-04 09:27:57]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:5048kb
  • [2024-10-04 09:27:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
const int N = 2e5 + 10;
const int P = 13333331;
const int b1 = 107, b2 = 233;
const int mod1 = 1e9 + 7, mod2 = 233333333;
pii in[N];
set<pii> hk;
pair<int, int> getHash(string s) {
  int r1 = 0, r2 = 0;
  for(int i = 0; s[i]; ++i) {
    r1 = ((r1 * 10) + (s[i] - '0')) % mod1;
    r2 = ((r2 * 10) + (s[i] - '0')) % mod2;
  }
  return {r1, r2};
}
pii add(pii a, pii b) {
  return {(a.fi + b.fi) % mod1, (a.se + b.se) % mod2};
}
signed main() {
//  cout << getHash("4").fi << '\n';
//  cout << getHash("6").fi << '\n';
//  cout << getHash("10").fi << '\n';
  int n, k;
  cin >> n >> k;
  string s, sk(k, '9');
  
  pii hk0 = getHash(sk), cur = {0, 0};
  for(int i = 1; i <= 20000; i++) {
    hk.insert(cur);
    cur = add(cur, hk0);
  }
  for(int i = 1; i <= n; i++) {
    cin >> s;
    in[i] = getHash(s);
  }
  
  int res = 0;
  for(int i = 1; i <= n; i++) {
    for(int j = i; j <= n; j++) {
      for(int k = j; k <= n; k++) {
        cur = add(add(in[i], in[j]), in[k]);
        res += hk.count(cur);
      }
    }
  }
  cout << res << '\n';
  
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 5048kb

input:

4 1
0
1
10
17

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Time Limit Exceeded

input:

500 859
7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...

output:


result: