답안 #657054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
657054 2022-11-08T19:37:15 Z bicsi Necklace (Subtask 1-3) (BOI19_necklace1) C++14
45 / 85
1500 ms 1152 KB
#include <bits/stdc++.h>

using namespace std;
using ld = long double;

using C = complex<ld>;
const ld EPS = 1e-3;

int main() {
  string s, t; cin >> s >> t;

  mt19937_64 rng(52);
  vector<C> rnd(256);
  for (int i = 0; i < 256; ++i) {
    ld real = 1.0L * rng() / rng.max();
    ld imag = 1.0L * rng() / rng.max();
    rnd[i] = C(real, imag);
    rnd[i] /= abs(rnd[i]);
  }

  auto cmp = [&](const pair<C, int>& aa, const pair<C, int>& bb) {
    auto& a = aa.first;
    auto& b = bb.first;
    if (abs(a.real() - b.real()) / 
        max(abs(a.real()), abs(b.real())) > EPS) 
      return a.real() < b.real();
    if (abs(a.imag() - b.imag()) / 
        max(abs(a.imag()), abs(b.imag())) > EPS) 
      return a.imag() < b.imag();
    return false;
  };

  auto check = [&](int len) {
    C eps = polar(1.0, 2.0 * M_PI / len);
    pair<int, int> ans = {-1, -1};
    for (int rev = 0; rev < 2; ++rev) {
      vector<pair<C, int>> vs, vt;
      for (int it = 0; it < 2; ++it) {
        C h = 0;
        for (int i = 0; i < (int)s.size(); ++i) {
          h = (h + rnd[s[i]]) * eps;
          if (i >= len - 1) {
            C now = pow(h, len);
            vs.emplace_back(now, i - len + 1);
            h -= rnd[s[i - len + 1]];
          }
        }
        swap(s, t); swap(vs, vt);
      }
      sort(vs.begin(), vs.end(), cmp);
      sort(vt.begin(), vt.end(), cmp);
      for (int i = 0, j = 0; i < (int)vs.size(); ++i) {
        while (j < vt.size() && !cmp(vs[i], vt[j])) {
          if (!cmp(vt[j], vs[i])) {
            ans.first = vs[i].second;
            ans.second = vt[j].second;
            if (rev) ans.first = s.size() - ans.first - len;
          }
          ++j;
        }
      }
      reverse(s.begin(), s.end());
    }
    return ans;
  };

  int ans = 0, ps = -1, pt = -1;
  for (int i = 1; i <= s.size(); ++i) {
    auto [a, b] = check(i);
    if (a >= 0) 
      ans = i, ps = a, pt = b;
  }
  cout << ans << endl << ps << " " << pt << endl;

  return 0;
}

Compilation message

necklace.cpp: In lambda function:
necklace.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::complex<long double>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while (j < vt.size() && !cmp(vs[i], vt[j])) {
      |                ~~^~~~~~~~~~~
necklace.cpp: In function 'int main()':
necklace.cpp:68:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for (int i = 1; i <= s.size(); ++i) {
      |                   ~~^~~~~~~~~~~
necklace.cpp:69:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   69 |     auto [a, b] = check(i);
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 5 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 4 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 5 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 4 ms 212 KB Output is correct
6 Correct 72 ms 360 KB Output is correct
7 Correct 62 ms 356 KB Output is correct
8 Correct 49 ms 340 KB Output is correct
9 Correct 60 ms 340 KB Output is correct
10 Correct 77 ms 364 KB Output is correct
11 Correct 61 ms 360 KB Output is correct
12 Correct 56 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 5 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 4 ms 212 KB Output is correct
6 Correct 72 ms 360 KB Output is correct
7 Correct 62 ms 356 KB Output is correct
8 Correct 49 ms 340 KB Output is correct
9 Correct 60 ms 340 KB Output is correct
10 Correct 77 ms 364 KB Output is correct
11 Correct 61 ms 360 KB Output is correct
12 Correct 56 ms 376 KB Output is correct
13 Execution timed out 1567 ms 1152 KB Time limit exceeded
14 Halted 0 ms 0 KB -