結果
問題 |
No.2419 MMA文字列2
|
ユーザー |
|
提出日時 | 2023-08-12 15:05:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 875 bytes |
コンパイル時間 | 1,817 ms |
コンパイル使用メモリ | 170,148 KB |
実行使用メモリ | 13,644 KB |
最終ジャッジ日時 | 2024-11-19 23:21:46 |
合計ジャッジ時間 | 48,084 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 WA * 7 TLE * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ string S; cin >> S; int l = S.length(); vector<int> dp(l+1,0); if(S[0] == S[1] && S[2] != S[1]){ dp[3] = 1; } ll next = 0; for(int i=4;i<=l;i++){ string re = S.substr(0,i-2); char x = S[i-2]; ll up = count(re.begin(),re.end(),x); if(x == S[i-1]){ dp[i]+=up; }else{ dp[i]+=up+next; next=0; } char y = S[i-1]; string re2 = S.substr(0,i-1); ll down = count(re2.begin(),re2.end(),y); if(down<2){ dp[i] += dp[i-1]; }else{ ll mi = down * (down-1)/2; dp[i] += dp[i-1]-mi; next = mi; } } for(int i=1;i<=l;i++){ dp[i] += dp[i-1]; } cout << dp[l] << endl; }