結果
| 問題 |
No.962 LCPs
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-11 14:52:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| コード長 | 1,096 bytes |
| コンパイル時間 | 2,019 ms |
| コンパイル使用メモリ | 202,380 KB |
| 最終ジャッジ日時 | 2025-01-09 17:22:46 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 64 |
ソースコード
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
void cmn(lint&x,lint y){if(x>y)x=y;}
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint n;std::cin>>n;
std::vector<std::string>s(n);
for(auto&&t:s)std::cin>>t;
std::vector<std::vector<lint>>a(n);
for(lint i=n-1;i>=0;i--){
auto&&now=a.at(i);
a.at(i).resize(s.at(i).length(),1);
if(i==n-1)continue;
auto&next=a.at(i+1);
for(lint j=0;j<(lint)std::min(now.size(),next.size());j++){
if(s.at(i).at(j)!=s.at(i+1).at(j))continue;
now.at(j)=next.at(j)+1;
if(j)cmn(now.at(j),now.at(j-1));
}
}
auto comb=[&](lint n){return n*(n+1)*(n+2)/6;};
lint ans=0;
for(lint i=0;i<n;i++){
for(lint j=0;j<(lint)a.at(i).size();j++){
if(i&&j<(lint)a.at(i-1).size()&&1<a.at(i-1).at(j))continue;
ans+=comb(a.at(i).at(j));
}
}
std::cout<<ans<<'\n';
}
ngtkana