Submission #656100

#TimeUsernameProblemLanguageResultExecution timeMemory
656100600MihneaNecklace (Subtask 4) (BOI19_necklace4)C++17
0 / 15
0 ms212 KiB
bool home = 1; bool verbose = 1; #include <bits/stdc++.h> using namespace std; mt19937 rng(7777); typedef long double ld; const ld PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914; using cd = complex<ld>; ld values[26]; cd get(string s, cd c) { cd sol = 0; cd cur = 1; for (int i = 0; i < (int) s.size(); i++) { assert('a' <= s[i] && s[i] <= 'z'); sol += cur * values[s[i] - 'a']; cur *= c; } return sol; } bool same(string s, string t) { assert((int) s.size() == (int) t.size()); int n = (int) s.size(); ld ang = 2 * PI / n; cd c(cos(ang), sin(ang)); /// get(s, c) == get(t, c) * c sau get(s, c) == get(t, c) * c^2 sau ... return abs(norm(get(s, c)) - norm(get(t, c))) < 1e-6; cd val = get(s, c) / get(t, c); cout << fixed << setprecision(3) << val << "\n"; cout << fixed << setprecision(3) << c << "\n"; cout << fixed << setprecision(3) << c * c << "\n"; cout << fixed << setprecision(3) << c * c * c << "\n"; } string s, t; bool isok(int len) { int n = (int) s.size(); int m = (int) t.size(); for (int i = 0; i + len - 1 < n; i++) { for (int j = 0; j + len - 1 < m; j++) { bool ok = same(string(s.begin() + i, s.begin() + i + len), string(t.begin() + j, t.begin() + j + len)); if (ok) { return 1; } } } return 0; } int main() { for (int x = 0; x < 26; x++) { values[x] = cos(rng()) * 10; } if (!home) { verbose = 0; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } if (home) { verbose = 1; freopen ("___input___.txt", "r", stdin); } cin >> s >> t; int n = (int) s.size(), m = (int) t.size(); int sol = min(n, m); while (!isok(sol)) { sol--; } cout << sol << "\n"; return 0; }

Compilation message (stderr)

necklace.cpp: In function 'int main()':
necklace.cpp:70:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     freopen ("___input___.txt", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...