# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
168379 | Thuleanx | 새로운 문제 (POI11_okr) | C++14 | 69 ms | 17884 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
vector<int> extract(char s[], int n) {
vector<int> pi(n);
pi[0] = 0;
for (int i = 1; i < n; i++) {
int j = pi[i-1];
while (j > 0 && s[i] != s[j])
j = pi[j-1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
vector<int> borders;
int j = n;
while (j>0) {
borders.push_back(j);
j = pi[j-1];
}
reverse(begin(borders), end(borders));
return borders;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
scanf("%d", &t);
stringstream ss;
char s[N];
while (t--) {
scanf("%s", s);
int n = string(s).length();
vector<int> p = extract(s,n); // all borders are here
// get seed
char ans[n+1];
if (p[0] == 1)
ans[0] = '0';
else for (int i = 0; i < p[0]; i++)
ans[i] = '0'+(i==p[0]-1);
for (int i = 1; i < p.size(); i++) {
if (p[i] - 2*p[i-1] <= 0) {
memcpy(ans+p[i-1], ans+2*p[i-1]-p[i], sizeof(char)*(p[i]-p[i-1]));
} else {
for (int j = p[i-1]; j < p[i]-p[i-1]; j++)
ans[j] = '0';
memcpy(ans+p[i]-p[i-1], ans, sizeof(char)*p[i-1]);
vector<int> border_now = extract(ans, p[i]); // O(n) but runs only O(\log{N}) time
if (!equal(begin(p), begin(p)+i+1, begin(border_now)))
ans[p[i]-p[i-1]-1] = '1';
}
}
ans[n] = 0;
ss << ans << endl;
}
cout << ss.str();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |