Submission #1611315
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
vector<vector<int>> next(n, vector<int>(26, n + 10));
vector<vector<int>> prev(n, vector<int>(26, -1));
vector<int> fir(26, n + 10);
int q;
cin >> q;
for (int i = 0; i < n; ++i) {
fir[s[i] - 'a'] = min(fir[s[i] - 'a'], i);
for (int j = i - 1; j >= 0; --j) {
next[j][s[i] - 'a'] = i;
if (s[j] == s[i]) break;
}
for (int j = i + 1; j < n; ++j) {
prev[j][s[i] - 'a'] = i;
if (s[j] == s[i]) break;
}
}
for (int i = 0; i < q; ++i) {
string t;
cin >> t;
int m = t.length();
int r = fir[t[0] - 'a'], l;
if (r >= n) {
cout << -1 << "\n";
continue;
}
for (int j = 1; j < m; ++j) {
r = next[r][t[j] - 'a'];
if (r >= n) {
cout << -1 << "\n";
goto A;
}
}
l = r;
for (int j = m - 2; j >= 0; --j) {
l = prev[l][t[j] - 'a'];
}
cout << l + 1 << " " << r + 1 << "\n";
A:
continue;
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - 極小部分列 |
| User | kurukurushuriken |
| Language | C++14 (GCC 5.4.1) |
| Score | 1 |
| Code Size | 1282 Byte |
| Status | AC |
| Exec Time | 240 ms |
| Memory | 27392 KiB |
Judge Result
| Set Name | sample | all | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 1 / 1 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| sample | sample-01.txt |
| all | sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, sample-01.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01-01.txt | AC | 28 ms | 512 KiB |
| 01-02.txt | AC | 31 ms | 640 KiB |
| 01-03.txt | AC | 33 ms | 27136 KiB |
| 01-04.txt | AC | 33 ms | 27008 KiB |
| 01-05.txt | AC | 240 ms | 27264 KiB |
| 01-06.txt | AC | 35 ms | 26880 KiB |
| 01-07.txt | AC | 38 ms | 26880 KiB |
| 01-08.txt | AC | 46 ms | 26880 KiB |
| 01-09.txt | AC | 67 ms | 27008 KiB |
| 01-10.txt | AC | 150 ms | 27136 KiB |
| 01-11.txt | AC | 36 ms | 27008 KiB |
| 01-12.txt | AC | 47 ms | 27008 KiB |
| 01-13.txt | AC | 49 ms | 27008 KiB |
| 01-14.txt | AC | 51 ms | 26880 KiB |
| 01-15.txt | AC | 35 ms | 26880 KiB |
| 01-16.txt | AC | 51 ms | 26880 KiB |
| 01-17.txt | AC | 49 ms | 26880 KiB |
| 01-18.txt | AC | 141 ms | 27392 KiB |
| sample-01.txt | AC | 1 ms | 256 KiB |