# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
479073 | Green55 | Round words (IZhO13_rowords) | C++17 | 303 ms | 344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define uint unsigned long long
#define ull unsigned __int128
const int LEN = 64;
const int MAX = 2205 + LEN;
inline bool at(uint a[], int i){
return a[i/LEN] & ((uint)1 << (i%LEN));
}
inline bool tog(uint a[], int i) {
return a[i/LEN] ^= ((uint)1 << (i%LEN));
}
int n;
uint a[MAX/LEN], b[MAX/LEN], cs[26][MAX/LEN];
void solve(uint c[]){
//sliding b -> a
memcpy(a, b, sizeof(b));
memset(b, 0, sizeof(b));
// b = (a << 1) | 1
uint carry = 1;
for(int i=0; i<n/LEN; ++i) {
b[i] = (a[i] << 1) | carry;
carry = bool(a[i] & ((uint)1<<(LEN-1)));
}
// b = -b = ~b + 1
for(int i=0; i<n/LEN; ++i) b[i] = ~b[i];
for(int i=0; i<n; ++i) if(tog(b, i)) break;
// a |= c, b += a, b &= a, b ^= a
carry = 0;
for(int i=0; i<n/LEN; ++i) {
a[i] |= c[i];
ull tmp = b[i]; tmp += a[i]; tmp += carry;
b[i] = tmp & (~(uint)0);
carry = tmp >> LEN;
b[i] &= a[i];
b[i] ^= a[i];
}
}
int solve_tc(string s, string t) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(cs, 0, sizeof(cs));
// init c['A'] ~ c['Z']
for(int i=0; i<t.size(); ++i) {
tog(cs[t[i] - 'a'], i);
}
n = (t.size()/LEN+1)*LEN;
for(int idx=0; idx<s.size(); ++idx) {
char c = s[idx];
solve(cs[c - 'a']);
}
int ret = 0;
for(int i=0; i<n; ++i){
ret += at(b, i);
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
string a, b;
cin >> a >> b;
int ans = 0;
for(int i=0; i<b.size(); ++i){
ans = max(ans, solve_tc(a, b));
b.push_back(b[0]);
b.erase(b.begin());
}
reverse(all(b));
for(int i=0; i<b.size(); ++i){
ans = max(ans, solve_tc(a, b));
b.push_back(b[0]);
b.erase(b.begin());
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |