이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstring>
#include <algorithm>
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 1e5 + 5;
const int Z = 26;
int dp [N][Z];
pair<int, int> q [N];
int snow [N];
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
string w;
cin >> w;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> q[i].first >> q[i].second;
--q[i].first; --q[i].second;
}
for (int i = 0; i < (int) w.size(); i++) {
cin >> snow[i];
--snow[i];
}
int lo = 0, hi = (int) w.size();
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
string cur = w;
for (int i = 0; i < mid; i++) {
cur[snow[i]] = '*';
}
memset (dp, 0, sizeof(dp));
for (int i = 0; i < (int) w.size(); i++) {
if (cur[i] != '*') ++dp[i][cur[i] - 'a'];
if (i) {
for (int j = 0; j < 26; j++) {
dp[i][j] += dp[i - 1][j];
}
}
}
bool valid = true;
for (int i = 0; i < n; i++) {
int baixo = q[i].first;
int cima = q[i].second;
for (int j = 0; j < 26; j++) {
int cnt = dp[cima][j] - (baixo - 1 < 0 ? 0 : dp[baixo - 1][j]);
valid &= (cnt <= 1);
}
}
if (valid) hi = mid;
else lo = mid + 1;
}
cout << hi << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |