結果
問題 | No.962 LCPs |
ユーザー | aajisaka |
提出日時 | 2019-12-26 00:12:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 2,627 bytes |
コンパイル時間 | 1,927 ms |
コンパイル使用メモリ | 176,668 KB |
実行使用メモリ | 10,328 KB |
最終ジャッジ日時 | 2024-10-01 13:04:42 |
合計ジャッジ時間 | 4,857 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 15 ms
10,328 KB |
testcase_18 | AC | 10 ms
6,784 KB |
testcase_19 | AC | 9 ms
6,784 KB |
testcase_20 | AC | 7 ms
5,760 KB |
testcase_21 | AC | 8 ms
5,760 KB |
testcase_22 | AC | 6 ms
5,248 KB |
testcase_23 | AC | 6 ms
5,248 KB |
testcase_24 | AC | 5 ms
5,248 KB |
testcase_25 | AC | 5 ms
5,248 KB |
testcase_26 | AC | 5 ms
5,248 KB |
testcase_27 | AC | 6 ms
5,376 KB |
testcase_28 | AC | 5 ms
5,248 KB |
testcase_29 | AC | 5 ms
5,248 KB |
testcase_30 | AC | 6 ms
5,248 KB |
testcase_31 | AC | 7 ms
5,760 KB |
testcase_32 | AC | 4 ms
5,248 KB |
testcase_33 | AC | 9 ms
6,656 KB |
testcase_34 | AC | 4 ms
5,248 KB |
testcase_35 | AC | 5 ms
5,248 KB |
testcase_36 | AC | 5 ms
5,248 KB |
testcase_37 | AC | 5 ms
5,248 KB |
testcase_38 | AC | 5 ms
5,248 KB |
testcase_39 | AC | 5 ms
5,248 KB |
testcase_40 | AC | 5 ms
5,248 KB |
testcase_41 | AC | 5 ms
5,248 KB |
testcase_42 | AC | 5 ms
5,248 KB |
testcase_43 | AC | 5 ms
5,248 KB |
testcase_44 | AC | 5 ms
5,248 KB |
testcase_45 | AC | 5 ms
5,248 KB |
testcase_46 | AC | 5 ms
5,248 KB |
testcase_47 | AC | 2 ms
5,248 KB |
testcase_48 | AC | 2 ms
5,248 KB |
testcase_49 | AC | 2 ms
5,248 KB |
testcase_50 | AC | 2 ms
5,248 KB |
testcase_51 | AC | 2 ms
5,248 KB |
testcase_52 | AC | 3 ms
5,248 KB |
testcase_53 | AC | 3 ms
5,248 KB |
testcase_54 | AC | 2 ms
5,248 KB |
testcase_55 | AC | 2 ms
5,248 KB |
testcase_56 | AC | 3 ms
5,248 KB |
testcase_57 | AC | 2 ms
5,248 KB |
testcase_58 | AC | 3 ms
5,248 KB |
testcase_59 | AC | 3 ms
5,248 KB |
testcase_60 | AC | 3 ms
5,248 KB |
testcase_61 | AC | 3 ms
5,248 KB |
testcase_62 | AC | 3 ms
5,248 KB |
testcase_63 | AC | 11 ms
7,816 KB |
testcase_64 | AC | 2 ms
5,248 KB |
testcase_65 | AC | 10 ms
7,808 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:64, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:7: In constructor 'constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U1 = long long int&; _U2 = int&; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = true; _T1 = long long int; _T2 = long long int]', inlined from 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::pair<long long int, long long int>; _Args = {long long int&, int&}; _Tp = std::pair<long long int, long long int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/new_allocator.h:175:4, inlined from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::pair<long long int, long long int>; _Args = {long long int&, int&}; _Tp = std::pair<long long int, long long int>]' at /home/linuxbrew/.linuxbrew/Cel
ソースコード
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aajisaka */ #include<bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr) #define rep(i,n) for(int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using P = pair<ll, ll>; constexpr double PI = 3.14159265358979323846; mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count()); class LCPs { public: void solve(istream& cin, ostream& cout) { SPEED; int n; cin >> n; vector<string> vec(n); ll ans = 0; rep(i, n) { cin >> vec[i]; ans += vec[i].size(); } vector<int> d(n); rep(i, n-1) { int j=0; while(j<vec[i].size() && j<vec[i+1].size() && vec[i][j] == vec[i+1][j]) { j++; } d[i] = j; } stack<P> st; rep(i, n) { if (st.empty() || st.top().second < d[i]) { st.emplace(i, d[i]); } else if (st.top().second == d[i]) { continue; } else { ll pf; while(!st.empty() && st.top().second > d[i]) { auto p = st.top(); st.pop(); ll low = d[i]; if (!st.empty()) chmax(low, st.top().second); ll k = p.second - low; ll r = i - p.first; pf = p.first; debug(k, r); ll now = r*(r+1)*(r+5)/6*k; ans += now; // k, r // (r+1) + r*2 + (r-1)*3 + ... + 2*r // r = 1 -> 2*1 = 2 // r = 2 -> 3*1 + 2*2 = 7 // r = 3 -> 4*1 + 3*2 + 2*3 = 16 // r = 4 -> 5*1 + 4*2 + 3*3 + 2*4 = 30 // r = 5 -> 6*1 + 5*2 + 4*3 + 3*4 + 2*5 = 50 // r = r -> r*(r+1)*(r+5)/6; } if (st.empty() || st.top().second < d[i]) { if (d[i] != 0) st.emplace(pf, d[i]); } } } cout << ans << endl; } }; signed main() { LCPs solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }