제출 #156439

#제출 시각아이디문제언어결과실행 시간메모리
156439jh05013원형 문자열 (IZhO13_rowords)C++17
100 / 100
195 ms548 KiB
#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) 메시지

rowords.cpp: In function 'int main()':
rowords.cpp:41:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<B.size(); i++){
                  ~^~~~~~~~~
rowords.cpp:46:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<B.size(); i++){
                  ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...