이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// iee
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define per(i, a, b) for (auto i = (a); i >= (b); --i)
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using namespace std;
void work(int);
template <class T> void read(T &x) {
x = 0; int f = 1, ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar();
x *= f;
}
int main() {
int TT = 1; // cin >> TT;
rep(CAS, 1, TT)
work(CAS);
return 0;
}
const int N = 1e5 + 5;
int n, q, p[N];
pair<int, int> qry[N];
char s[N], now[N], S[N][26];
bool ok(int mid) {
memcpy(now, s, sizeof s);
rep(i, 1, mid) now[p[i]] = '*';
rep(i, 1, n) {
rep(j, 0, 25) S[i][j] = S[i - 1][j];
if (now[i] != '*') S[i][now[i] - 'a']++;
}
rep(i, 1, q) {
rep(j, 0, 25) {
if (S[qry[i].se][j] - S[qry[i].fi - 1][j] > 1) return 0;
}
}
return 1;
}
void work(int CASE) {
scanf("%s", s + 1);
n = strlen(s + 1);
cin >> q;
rep(i, 1, q) {
cin >> qry[i].fi >> qry[i].se;
}
rep(i, 1, n) {
cin >> p[i];
}
int l = 0, r = n;
while (l < r) {
int mid = l + r >> 1;
if (ok(mid)) r = mid;
else l = mid + 1;
}
cout << l;
}
컴파일 시 표준 에러 (stderr) 메시지
grudanje.cpp: In function 'void work(int)':
grudanje.cpp:62:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
62 | int mid = l + r >> 1;
| ~~^~~
grudanje.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%s", s + 1);
| ~~~~~^~~~~~~~~~~~~
# | 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... |