結果
問題 |
No.8015 アンチローリングハッシュ
|
ユーザー |
|
提出日時 | 2024-05-17 01:59:16 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,620 bytes |
コンパイル時間 | 2,374 ms |
コンパイル使用メモリ | 116,216 KB |
実行使用メモリ | 15,184 KB |
最終ジャッジ日時 | 2024-12-20 11:26:04 |
合計ジャッジ時間 | 5,182 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 WA * 3 |
ソースコード
#include <algorithm> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; using ll = long long; #define rep(i, j, n) for (ll i = j; i < (n); ++i) #define rrep(i, j, n) for (ll i = (n) - 1; j <= i; --i) #define all(a) a.begin(), a.end() template <typename T> std::ostream &operator<<(std::ostream &os, std::vector<T> &a) { for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? " " : "") << a[i]; return os << '\n'; } template <typename T> std::istream &operator>>(std::istream &is, std::vector<T> &a) { for (T &x : a) { is >> x; } return is; } //[[maybe_unused]] constexpr long long MOD = 998244353; // constexpr long long MOD = 1000000007; [[maybe_unused]] constexpr int INF = 0x3f3f3f3f; [[maybe_unused]] constexpr long long INFL = 0x3f3f3f3f3f3f3f3fLL; int main() { cin.tie(0)->sync_with_stdio(0); // ll a, b; cin >> a >> b; string s; char c = 0; rep(i, 0, b * 10) { s += c + 'a'; c = (c + 3) % 26; } int n = (int)s.size(); vector<ll> hash(n + 1); rep(i, 0, n) { hash[i + 1] = (hash[i] * a + s[i]) % b; } vector<ll> mp(b); rep(i, 0, n) mp[hash[i]]++; ll mx = 0, mxi = 0; rep(i, 0, b) if (mx < mp[i]) mx = mp[i], mxi = i; vector<int> ids; rep(i, 0, n) if (hash[i] == mxi) ids.push_back(i); int id1 = ids[0], id2 = ids[1], id3 = ids[2], id4 = ids[3]; if (id2 - id1 == id4 - id3) id4 = ids[4]; string t = s.substr(0, id1) + s.substr(id3, id4 - id3) + s.substr(id2, id3 - id2) + s.substr(id1, id2 - id1) + s.substr(id4, n - id4); cout << s << '\n' << t << '\n'; }