# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
48766 |
2018-05-18T16:33:43 Z |
leejseo |
구간 성분 (KOI15_interval) |
C++17 |
|
969 ms |
34028 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<pii, int> tri;
char A[1505], B[1505];
int N, M, va[1505], vb[1505], cha[27][1505], chb[27][1505], sa[1505], sb[1505], ans = 0, hsh[27];
vector<tri> inb;
vector<pii> inb_v;
int ub(pii val){
int count = inb_v.size();
int first = 0;
while (count > 0){
int step = count / 2;
int mid = first + step;
if (!(val < inb_v[mid])) first = ++mid, count -= step + 1;
else count = step;
}
return first;
}
int lb(pii val){
int count = inb_v.size();
int first = 0;
while (count > 0){
int step = count / 2;
int mid = first + step;
if (inb_v[mid] < val) first = ++mid, count -= step + 1;
else count = step;
}
return first;
}
int main(void){
hsh[0] = 987654337;
scanf("%s", A);
scanf("%s", B);
N = strlen(A), M = strlen(B);
for (int i=1; i<27; i++) hsh[i] = hsh[i-1] * hsh[0];
for (int i=0; i<N; i++){
va[i] = A[i] - 96;
for (int c=1; c<27; c++) cha[c][i+1] = cha[c][i];
cha[va[i]][i+1]++;
va[i] = hsh[va[i]];
sa[i+1] = sa[i] + va[i];
}
for (int i=0; i<M; i++) {
vb[i] = B[i] - 96;
for (int c=1; c<27; c++) chb[c][i+1] = chb[c][i];
chb[vb[i]][i+1]++;
vb[i] = hsh[vb[i]];
sb[i+1] = sb[i] + vb[i];
}
for (int k=0; k<M; k++){
for (int i=0; i<M-k; i++){
inb.push_back(tri(pii(sb[i+k+1] - sb[i], k), i));
inb_v.push_back(pii(sb[i+k+1] - sb[i], k));
}
}
sort(inb.begin(), inb.end());
sort(inb_v.begin(), inb_v.end());
for (int k=0; k<N; k++){
for (int i=0; i<N-k; i++){
if (ans == k+1) break;
int val = sa[i+k+1] - sa[i];
int st = lb(pii(val, k)), ed = ub(pii(val, k));
for (int j=st; j<ed; j++){
if (k+1 == ans) break;
int nv, nk = (inb[j].first).first, ni = inb[j].second;
bool b = true;
for (int c=1; c<27; c++){
if (cha[c][i+k+1] - cha[c][i] != chb[c][ni+k+1] - chb[c][ni]){
b = false;
break;
}
}
if (b) ans = max(ans, k+1);
}
}
}
printf("%d\n", ans);
}
Compilation message
interval.cpp: In function 'int main()':
interval.cpp:71:9: warning: unused variable 'nv' [-Wunused-variable]
int nv, nk = (inb[j].first).first, ni = inb[j].second;
^~
interval.cpp:71:13: warning: unused variable 'nk' [-Wunused-variable]
int nv, nk = (inb[j].first).first, ni = inb[j].second;
^~
interval.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", A);
~~~~~^~~~~~~~~
interval.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", B);
~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
4 ms |
940 KB |
Output is correct |
4 |
Correct |
4 ms |
940 KB |
Output is correct |
5 |
Correct |
5 ms |
940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
3488 KB |
Output is correct |
2 |
Correct |
47 ms |
3488 KB |
Output is correct |
3 |
Correct |
29 ms |
3600 KB |
Output is correct |
4 |
Correct |
18 ms |
3600 KB |
Output is correct |
5 |
Correct |
66 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
323 ms |
10864 KB |
Output is correct |
2 |
Correct |
362 ms |
10864 KB |
Output is correct |
3 |
Correct |
349 ms |
10864 KB |
Output is correct |
4 |
Correct |
348 ms |
10864 KB |
Output is correct |
5 |
Correct |
345 ms |
10944 KB |
Output is correct |
6 |
Correct |
357 ms |
10944 KB |
Output is correct |
7 |
Correct |
336 ms |
10944 KB |
Output is correct |
8 |
Correct |
343 ms |
10944 KB |
Output is correct |
9 |
Correct |
343 ms |
10944 KB |
Output is correct |
10 |
Correct |
356 ms |
10944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
17528 KB |
Output is correct |
2 |
Correct |
905 ms |
34012 KB |
Output is correct |
3 |
Correct |
879 ms |
34016 KB |
Output is correct |
4 |
Correct |
392 ms |
34028 KB |
Output is correct |
5 |
Correct |
969 ms |
34028 KB |
Output is correct |