QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#406281 | #6825. Expenditure Reduction | james1BadCreeper# | WA | 2ms | 8292kb | C++17 | 928b | 2024-05-07 08:41:31 | 2024-05-07 08:41:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 1e5 + 5;
int n, m;
char s[N], f[N];
set<int> pos[N];
void solve(void) {
cin >> s + 1 >> f + 1; n = strlen(s + 1); m = strlen(f + 1);
for (int i = 1; i <= n; ++i) pos[s[i]].insert(i);
int ans = 1e9, l = 0, r = 0;
for (int x : pos[f[1]]) {
int i = x, flg = 1;
for (int j = 2; j <= m; ++j) {
auto it = pos[f[j]].upper_bound(i);
if (it == pos[f[j]].end()) { flg = 0; break; }
i = *it;
}
if (flg) {
if (i - x + 1 < ans)
ans = i - x + 1, l = x, r = i;
}
}
// cout << l << " " << r << "\n";
for (int i = l; i <= r; ++i) cout << s[i];
cout << "\n";
}
int main(void) {
ios::sync_with_stdio(0);
int T = 1; cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 8292kb
input:
4 114514 15 shanghaicpc ac aaabbbaaabbbccc abc howdeliciousandfreshitis oishii
output:
145 aic abb owdeliciousandfreshiti
result:
wrong answer Participant's answer doesn't contain abc as subsequence (test case 3)