Submission #46596008
Source Code Expand
#include <bits/stdc++.h> #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif using int64 = long long; using uint = unsigned int; using uint64 = unsigned long long; bool ckmin(auto& a, auto b) { return b < a ? a = b, 1 : 0; } bool ckmax(auto& a, auto b) { return b > a ? a = b, 1 : 0; } using namespace std; struct Fenwick { int n; vector<int> a; Fenwick(int n_) : n(n_ + 1) { a.resize(n); } void Change(int x, int dx) { while (x < n) { a[x] += dx; x |= (x + 1); } } int GetSum(int x) { int res = 0; while (x >= 0) { res += a[x]; x = (x & (x + 1)) - 1; } return res; } int RangeSum(int l, int r) { auto res = GetSum(r); if (l > 0) res -= GetSum(l - 1); return res; } }; int Go(string& a, string& b) { int i = 0, j = 0, res = 0; while (i < (int)a.length() && j < (int)b.length()) { if (a[i] == b[j]) { res++, i++, j++; } else { j++; } } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; string t; cin >> n >> t; string tr = t; reverse(tr.begin(), tr.end()); int len = t.length(); vector<string> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int64 ans = 0; auto Work = [&](int ttt) { Fenwick fw(500005); for (int i = 0; i < n; i++) { auto s = a[i]; int l = Go(t, s); reverse(s.begin(), s.end()); int r = Go(tr, s); if (ttt) fw.Change(r, 1); ans += fw.RangeSum(len - l, 500000); if (!ttt) fw.Change(r, 1); debug(i, l, r, ans); } }; Work(0); reverse(a.begin(), a.end()); Work(1); cout << ans << '\n'; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Joint Two Strings |
User | xindubawukong |
Language | C++ 20 (gcc 12.2) |
Score | 500 |
Code Size | 1750 Byte |
Status | AC |
Exec Time | 63 ms |
Memory | 21876 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 | 54 ms | 20812 KiB |
001.txt | AC | 56 ms | 20744 KiB |
002.txt | AC | 4 ms | 6048 KiB |
003.txt | AC | 5 ms | 6136 KiB |
004.txt | AC | 9 ms | 6184 KiB |
005.txt | AC | 9 ms | 5992 KiB |
006.txt | AC | 10 ms | 7196 KiB |
007.txt | AC | 10 ms | 7096 KiB |
008.txt | AC | 2 ms | 5408 KiB |
009.txt | AC | 58 ms | 20740 KiB |
010.txt | AC | 24 ms | 8824 KiB |
011.txt | AC | 38 ms | 12480 KiB |
012.txt | AC | 11 ms | 6576 KiB |
013.txt | AC | 13 ms | 6660 KiB |
014.txt | AC | 23 ms | 8780 KiB |
015.txt | AC | 4 ms | 6096 KiB |
016.txt | AC | 10 ms | 6144 KiB |
017.txt | AC | 9 ms | 6164 KiB |
018.txt | AC | 9 ms | 6092 KiB |
019.txt | AC | 4 ms | 6176 KiB |
020.txt | AC | 4 ms | 6124 KiB |
021.txt | AC | 8 ms | 6064 KiB |
022.txt | AC | 9 ms | 6100 KiB |
023.txt | AC | 9 ms | 5992 KiB |
024.txt | AC | 3 ms | 6040 KiB |
025.txt | AC | 4 ms | 6084 KiB |
026.txt | AC | 4 ms | 6024 KiB |
027.txt | AC | 7 ms | 6084 KiB |
028.txt | AC | 9 ms | 6040 KiB |
029.txt | AC | 9 ms | 6000 KiB |
030.txt | AC | 3 ms | 5992 KiB |
031.txt | AC | 3 ms | 6036 KiB |
032.txt | AC | 4 ms | 6028 KiB |
033.txt | AC | 5 ms | 6132 KiB |
034.txt | AC | 8 ms | 6060 KiB |
035.txt | AC | 9 ms | 6108 KiB |
036.txt | AC | 8 ms | 6216 KiB |
037.txt | AC | 63 ms | 21848 KiB |
038.txt | AC | 63 ms | 21876 KiB |
039.txt | AC | 62 ms | 21868 KiB |
example0.txt | AC | 2 ms | 5548 KiB |
example1.txt | AC | 2 ms | 5480 KiB |
example2.txt | AC | 2 ms | 5396 KiB |
example3.txt | AC | 2 ms | 5552 KiB |