이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
string a;
int q, n, d[100001], suffix_arr[26][100001];
pair <int, int> query[100001];
bool ok(int x) {
string z = a;
for (int i = 1; i <= x; ++ i) {
z[d[i]] = '*';
}
// cout << z << endl;
for (int i = 0; i <= 25; ++ i)
suffix_arr[i][0] = 0;
for (int i = 1; i <= n; ++ i) {
for (int j = 0; j <= 25; ++ j)
suffix_arr[j][i] = 0;
if (z[i] != '*') {
suffix_arr[int(z[i] - 'a')][i] = 1;
}
for (int j = 0; j <= 25; ++ j) {
suffix_arr[j][i] += suffix_arr[j][i-1];
}
}
for (int i = 1; i <= q; ++ i) {
for (int j = 0; j <= 25; ++ j) {
if (suffix_arr[j][query[i].se] - suffix_arr[j][query[i].fi - 1] > 1) return false;
}
}
return true;
}
int main() {
//freopen(".INP", "r", stdin);
//freopen(".OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> a;
n = a.size();
a = '0' + a;
cin >> q;
for (int i = 1; i <= q; ++ i) {
cin >> query[i].fi >> query[i].se;
}
for (int i = 1; i <= n; ++ i) {
cin >> d[i];
}
int l = 0, r = n, ans;
while (l <= r) {
int mid = (l + r) / 2;
if (ok(mid)) {
r = mid - 1;
ans = mid;
}
else l = mid + 1;
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
grudanje.cpp: In function 'int main()':
grudanje.cpp:69:13: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
69 | cout << ans;
| ^~~
# | 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... |