結果
問題 | No.962 LCPs |
ユーザー |
|
提出日時 | 2020-01-10 11:31:26 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,587 bytes |
コンパイル時間 | 1,452 ms |
コンパイル使用メモリ | 109,480 KB |
実行使用メモリ | 9,412 KB |
最終ジャッジ日時 | 2024-11-23 21:46:13 |
合計ジャッジ時間 | 4,330 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 64 |
ソースコード
#include <iostream> #include <vector> #include <array> #include <list> #include <string> #include <stack> #include <queue> #include <deque> #include <unordered_map> #include <unordered_set> #include <tuple> #include <memory> #include <cmath> #include <algorithm> #include <functional> #include <iomanip> #include <numeric> #include <climits> #include <cfloat> #include <cassert> #include <random> int main() { int n; std::cin >> n; std::vector<std::string> words(n); for (auto& w : words) std::cin >> w; std::queue<std::pair<int, int>> queue; const auto max_length = std::max_element(words.begin(), words.end(), [](const std::string& a, const std::string& b) { return a.size() < b.size(); })->size(); queue.emplace(0, n); long long int result = 0; for (auto i = 0; i < max_length; ++i) { for (auto size = queue.size(); size > 0; --size) { const auto top = queue.front(); queue.pop(); int prev = -1; for (auto j = top.first; j < top.second; ++j) { if (i >= words[j].size()) { if (prev != -1) { queue.emplace(prev, j); result += (j - prev) * (j - prev + 1LL) * (j - prev + 2LL) / 6; prev = -1; } } else if (prev != -1) { if (words[prev][i] != words[j][i]) { queue.emplace(prev, j); result += (j - prev) * (j - prev + 1LL) * (j - prev + 2LL) / 6; prev = j; } } else { prev = j; } } if (prev != -1) { queue.emplace(prev, top.second); result += (top.second - prev) * (top.second - prev + 1LL) * (top.second - prev + 2LL) / 6; } } } std::cout << result << std::endl; }