結果
問題 | No.958 たぷりすたべる (回文) |
ユーザー |
![]() |
提出日時 | 2019-12-21 11:17:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 403 ms / 2,000 ms |
コード長 | 1,484 bytes |
コンパイル時間 | 2,753 ms |
コンパイル使用メモリ | 170,592 KB |
実行使用メモリ | 8,812 KB |
最終ジャッジ日時 | 2024-07-19 04:33:42 |
合計ジャッジ時間 | 11,891 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 53 |
コンパイルメッセージ
main.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 46 | main() | ^~~~
ソースコード
#include <bits/stdc++.h> #ifndef MANACHER_HPP #define MANACHER_HPP template <class str_t> class Manacher { const size_t len; std::vector<size_t> rad; friend std::ostream &operator<<(std::ostream &s, const Manacher &mana) { bool is_front = true; for(size_t r : mana.rad) { if(is_front) is_front = false; else s << " "; s << r; } return s; } public: Manacher(const str_t &str) : len(str.size()), rad(str.size()) { for(size_t i = 0, c = 0; i != len; ++i) { int l = c * 2 - i; if(l >= 0 && c + rad[c] > i + rad[l]) rad[i] = rad[l]; else { size_t j = c + rad[c] - i; while(i >= j && i + j != len && str[i - j] == str[i + j]) ++j; rad[c = i] = j; } } } size_t size() const { return rad.size(); } size_t operator[](size_t i) const { return rad[i]; } }; // class Manacher #endif using namespace std; using i64=int_least64_t; main() { i64 n,k,Q; cin>>n>>k>>Q; string s; cin>>s; Manacher<string> mana(s+s+s); for(; Q--; ) { i64 a; cin>>a; --a; i64 b=a%n+n; i64 r=mana[b]; i64 ans; if(r<n) { r=min({r,a+1,n*k-a}); ans=2*r-1; } else { ans=2*min(a+1,n*k-a)-1; } cout << ans << "\n"; } }