# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
156439 | jh05013 | 원형 문자열 (IZhO13_rowords) | C++17 | 195 ms | 548 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define entire(X) X.begin(),X.end()
using namespace std; typedef long long ll;
void OJize(){cin.tie(NULL); ios_base::sync_with_stdio(false);}
template <class T1, class T2>ostream&operator<<(ostream &os,pair<T1,T2>const&x){os<<'('<<x.first<<", "<<x.second<<')';return os;}
template <class Ch, class Tr, class Container>basic_ostream<Ch,Tr>&operator<<(basic_ostream<Ch,Tr>&os,Container const&x){for(auto&y:x)os<<y<<" ";return os;}
#define GET(arr, x) (((arr[x >> 6] >> (x & 63)) & 1) == 1)
#define SET(arr, x) (arr[x >> 6] |= 1llu << (x & 63))
typedef unsigned long long ull;
int lcs(string A, string B){
int N = A.size(), M = B.size(), sz = (M>>6)+1;
vector<vector<ull>> S(256, vector<ull>(sz));
for(int j=0; j<M; j++) SET(S[B[j]], j);
vector<ull> row(sz);
for(int j=0; j<M; j++) if(A[0] == B[j]){SET(row, j); break;}
for(int i=1; i<N; i++){
ull shl_carry = 1, minus_carry = 0;
for(int k=0; k<sz; k++){
ull x_k = S[A[i]][k] | row[k];
ull term_1 = (row[k] << 1) | shl_carry;
shl_carry = row[k] >> 63;
auto sub_carry = [](ull &x, ull y){
ull tmp = x; return (x = tmp-y) > tmp;
};
ull term_2 = x_k;
minus_carry = sub_carry(term_2, minus_carry);
minus_carry += sub_carry(term_2, term_1);
row[k] = x_k & (x_k ^ term_2);
}
row[M >> 6]&= (1llu << (M & 63)) - 1;
}
int ret = 0;
for(int j=0; j<M; j++) if(GET(row, j)) ret++;
return ret;
}
int main(){OJize();
string A, B; cin>>A>>B;
int ans = 0;
for(int i=0; i<B.size(); i++){
rotate(B.begin(), B.begin()+1, B.end());
ans = max(ans, lcs(A, B));
}
reverse(entire(B));
for(int i=0; i<B.size(); i++){
rotate(B.begin(), B.begin()+1, B.end());
ans = max(ans, lcs(A, B));
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |