Submission #61443294
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
int prefix_counter(string &s,string &t){
int m = t.size();
int idx = 0;
int count = 0;
for(char c : s){
if(c==t[idx]){
idx++;
count++;
}
if(idx>=m) {
return count;
}
}
return count;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string t;
cin >> n >> t;
string revt = t;
ranges::reverse(revt);
vector<string> s(n);
for(int i=0;i<n;++i)cin>>s[i];
vector<vector<int>> ps_count(2,vector<int>(n));;
for(int i=0;i<n;++i){
ps_count[0][i] = prefix_counter(s[i],t);
ranges::reverse(s[i]);
ps_count[1][i] = prefix_counter(s[i],revt);
}
ranges::sort(ps_count[0]);
ranges::sort(ps_count[1]);
ll ans = 0;
/*
const auto &it = ps_count[1];
for(int i=0;i<n;++i){
int target = (int)t.size() - ps_count[0][i];
ans += end(it) - lower_bound(begin(it),end(it),target);
}
*/
int r=n-1;
for(int i=0;i<n;++i){
int req = (int)t.size() - ps_count[0][i];
while(r>=0 && ps_count[1][r] >= req){
--r;
}
ans += n-r-1;
}
cout << ans << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Joint Two Strings |
| User | ponzoie |
| Language | C++ 23 (Clang 16.0.6) |
| Score | 500 |
| Code Size | 1429 Byte |
| Status | AC |
| Exec Time | 43 ms |
| Memory | 25768 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt, example3.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, example0.txt, example1.txt, example2.txt, example3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 39 ms | 24720 KiB |
| 001.txt | AC | 38 ms | 24404 KiB |
| 002.txt | AC | 2 ms | 4060 KiB |
| 003.txt | AC | 2 ms | 3988 KiB |
| 004.txt | AC | 4 ms | 4024 KiB |
| 005.txt | AC | 4 ms | 3992 KiB |
| 006.txt | AC | 5 ms | 4912 KiB |
| 007.txt | AC | 5 ms | 4916 KiB |
| 008.txt | AC | 1 ms | 3412 KiB |
| 009.txt | AC | 43 ms | 24780 KiB |
| 010.txt | AC | 16 ms | 8240 KiB |
| 011.txt | AC | 27 ms | 13468 KiB |
| 012.txt | AC | 6 ms | 5052 KiB |
| 013.txt | AC | 7 ms | 5288 KiB |
| 014.txt | AC | 15 ms | 8120 KiB |
| 015.txt | AC | 2 ms | 4068 KiB |
| 016.txt | AC | 5 ms | 4648 KiB |
| 017.txt | AC | 4 ms | 4152 KiB |
| 018.txt | AC | 5 ms | 4064 KiB |
| 019.txt | AC | 2 ms | 4052 KiB |
| 020.txt | AC | 2 ms | 4108 KiB |
| 021.txt | AC | 4 ms | 3900 KiB |
| 022.txt | AC | 4 ms | 4092 KiB |
| 023.txt | AC | 4 ms | 4020 KiB |
| 024.txt | AC | 2 ms | 3792 KiB |
| 025.txt | AC | 2 ms | 4048 KiB |
| 026.txt | AC | 2 ms | 3892 KiB |
| 027.txt | AC | 3 ms | 3820 KiB |
| 028.txt | AC | 4 ms | 3860 KiB |
| 029.txt | AC | 4 ms | 4164 KiB |
| 030.txt | AC | 2 ms | 3852 KiB |
| 031.txt | AC | 2 ms | 3924 KiB |
| 032.txt | AC | 2 ms | 3980 KiB |
| 033.txt | AC | 2 ms | 3628 KiB |
| 034.txt | AC | 4 ms | 3800 KiB |
| 035.txt | AC | 4 ms | 3916 KiB |
| 036.txt | AC | 4 ms | 3872 KiB |
| 037.txt | AC | 40 ms | 25664 KiB |
| 038.txt | AC | 40 ms | 25768 KiB |
| 039.txt | AC | 41 ms | 25768 KiB |
| example0.txt | AC | 1 ms | 3428 KiB |
| example1.txt | AC | 1 ms | 3488 KiB |
| example2.txt | AC | 1 ms | 3492 KiB |
| example3.txt | AC | 1 ms | 3464 KiB |