QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#579687#9222. Price ComboisaunoyaWA 16ms81904kbC++233.4kb2024-09-21 17:02:452024-09-21 17:02:45

Judging History

This is the latest submission verdict.

  • [2024-09-21 17:02:45]
  • Judged
  • Verdict: WA
  • Time: 16ms
  • Memory: 81904kb
  • [2024-09-21 17:02:45]
  • Submitted

answer


#include <chrono>
#include <unordered_map>
struct splitmix64_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        std::chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

template <typename K, typename V, typename Hash = splitmix64_hash>
using HashMap = std::unordered_map<K, V, Hash>;


#if defined(local)
#include "../my_template_compiled.hpp"
#else
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#define rep1(a) for (int i = 0; i < a; i++)
#define rep2(i, a) for (int i = 0; i < a; i++)
#define rep3(i, a, b) for (int i = a; i < b; i++)
#define rep4(i, a, b, c) for (int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb emplace_back
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
  x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
  x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> using vc = vector<T>;
const int INF = 1000000000;
const ll LNF = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
#endif

namespace noya {}


const double p = (1. + sqrt(5)) / 2.;
const double w = log10(p);
const int FM = 1e7;

const int P1 = 1e9 + 7;
const int P2 = 1e9 + 9;

using namespace noya;
pair<int, int> F[FM];
pair<int, int> add(pair<int, int> a, pair<int, int> b) {
  int x = a.first + b.first;
  int y = a.second + b.second;
  if (x >= P1)
    x -= P1;
  if (y >= P2)
    y -= P2;
  return make_pair(x, y);
}
pair<int, int> sub(pair<int, int> a, pair<int, int> b) {
  int x = a.first - b.first;
  int y = a.second - b.second;
  if (x < 0)
    x += P1;
  if (y < 0)
    y += P2;
  return make_pair(x, y);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;
  vector<string> S(N);

  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    p[i] = i;
  }

  sort(p.begin(), p.end(),
       [&](int i, int j) { return S[i].size() < S[j].size(); });

  F[1] = F[2] = {1, 1};

  for (int i = 3; i < FM; i++) {
    F[i] = add(F[i - 2], F[i - 1]);
  }

  long long ans = 0;
  HashMap<int, int> cnt;
  for (int i : p) {
    int sz = int(S[i].size());
    long long cur1 = 0;
    long long cur2 = 0;
    for (auto c : S[i]) {
      int d = c - '0';
      cur1 = (cur1 * 10 + d) % P1;
      cur2 = (cur2 * 10 + d) % P2;
    }
    int lim = sz / w;
    pair<int, int> cur = make_pair(cur1, cur2);
    for (int j = max(lim - 5, 1); j < min(lim + 15, FM); j++) {
      auto [a, b] = sub(F[j], cur);
      long long F = 1ll * a * P2 + b;
      if (cnt.count(F))
        ans += cnt[F];
    }
    long long X = 1ll * cur1 * P2 + cur2;
    cnt[X] += 1;
  }
  cout << ans << "\n";
}

详细

Test #1:

score: 0
Wrong Answer
time: 16ms
memory: 81904kb

input:

7
10 12 19 99 10 8 49
9 14 15 199 11 7 19

output:

0

result:

wrong answer 1st lines differ - expected: '131', found: '0'