# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
854907 | 2023-09-29T10:33:12 Z | aymanrs | Necklace (Subtask 1-3) (BOI19_necklace1) | C++14 | 271 ms | 225364 KB |
#include<bits/stdc++.h> using namespace std; struct node { node* nx[26]={NULL}; short st=-1; }; void del(node*r){ if(!r)return; for(int i = 0;i < 26;i++) del(r->nx[i]); delete r; } char S[10000], F[10000]; int N; int leastrot(){ fill(F, F+N, -1); int k = 0; for(int i = 1; i < N; i++){ char c = S[i]; int f = F[i-k-1]; while(f != -1 && c != S[k+f+1]){ if(c < S[k+f+1]) k = i-f-1; f = F[f]; } if(c != S[k+f+1]){ if(c < S[k]) k = i; F[i-k] = -1; } else F[i-k] = f+1; } return k; } void add(node* r, int l){ int f = leastrot(); for(int i = 0;i < (N>>1);i++){ S[f+i]-='a'; if(!r->nx[S[f+i]]) r->nx[S[f+i]] = new node; r = r->nx[S[f+i]]; } r->st = l; } short fi(node* r){ int f = leastrot(); for(int i = 0;i < (N>>1);i++){ S[f+i]-='a'; if(!r->nx[S[f+i]]) return -1; r = r->nx[S[f+i]]; } return r->st; } void solve(){ string a, b;cin >> a >> b; int n = a.size(), m = b.size(); node* r = new node; for(int i = 0;i < n;i++) for(int j = 1;i+j <= n;j++) { N = j<<1; for(int k = 0;k < j;k++) S[k] = S[k+j] = a[i+k]; add(r, i); } reverse(a.begin(), a.end()); for(int i = 0;i < n;i++) for(int j = 1;i+j <= n;j++) { N = j<<1; for(int k = 0;k < j;k++) S[k] = S[k+j] = a[i+k]; add(r, n-i-j); } for(int j = m;j >= 1;j--) for(int i = 0;i+j <= m;i++){ N = j<<1; for(int k = 0;k < j;k++) S[k] = S[k+j] = b[i+k]; int f = fi(r); if(f != -1){ cout << j << '\n' << f << ' ' << i << '\n'; return; } } del(r); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); solve(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 3676 KB | Output is correct |
2 | Correct | 5 ms | 3164 KB | Output is correct |
3 | Correct | 4 ms | 3164 KB | Output is correct |
4 | Correct | 11 ms | 11296 KB | Output is correct |
5 | Correct | 21 ms | 32860 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 3676 KB | Output is correct |
2 | Correct | 5 ms | 3164 KB | Output is correct |
3 | Correct | 4 ms | 3164 KB | Output is correct |
4 | Correct | 11 ms | 11296 KB | Output is correct |
5 | Correct | 21 ms | 32860 KB | Output is correct |
6 | Correct | 247 ms | 24432 KB | Output is correct |
7 | Runtime error | 271 ms | 225364 KB | Execution killed with signal 11 |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 3676 KB | Output is correct |
2 | Correct | 5 ms | 3164 KB | Output is correct |
3 | Correct | 4 ms | 3164 KB | Output is correct |
4 | Correct | 11 ms | 11296 KB | Output is correct |
5 | Correct | 21 ms | 32860 KB | Output is correct |
6 | Correct | 247 ms | 24432 KB | Output is correct |
7 | Runtime error | 271 ms | 225364 KB | Execution killed with signal 11 |
8 | Halted | 0 ms | 0 KB | - |