Submission #596915

# Submission time Handle Problem Language Result Execution time Memory
596915 2022-07-15T09:18:02 Z jy0n Round words (IZhO13_rowords) C++17
68 / 100
206 ms 296 KB
#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;

const int Sigma= 26;
string A, B;
vector<ull> d, s[Sigma];

#define set_bit(bs, i) (bs[i>>6] |= 1llu << (i&63))
#define get_bit(bs, i) ((bs[i>>6] >> (i&63))&1)
#define sub(a, b) ((a-b>a)? (a-=b, 1) : (a-=b, 0))

int main() {
    cin >> A >> B;
    int n = (int)A.size(), m = (int)B.size(), l = (m>>6)+1, ans=0;
    d.resize(l);
    for (int i=0; i<Sigma; ++i) s[i].resize(l);
    for (int i=0; i<m; ++i) set_bit(s[B[i]-'a'], i);
    for (int k=0; k<n; ++k) {
        memset(&d[0], 0, sizeof(ull)*l);
        for (int i=0; i<m; ++i) if (A[k] == B[i]) { set_bit(d, i); break; }
        for (int i=1; i<n; ++i) {
            ull sc = 1, mc = 0;
            for (int j=0; j<l; ++j) {
                ull x = s[A[(k+i)%n]-'a'][j]|d[j];
                ull t = (d[j] << 1)|sc;
                sc = d[j] >> 63;
                ull tt = x;
                mc = sub(tt, mc) + sub(tt, t);
                d[j] = x&(x^tt);
            }
        }
        int ret = 0;
        for (int i=0; i<m; ++i) ret += get_bit(d, i);
        ans=max(ans, ret);
    }
    for (int i=0; i<Sigma; ++i) memset(&s[i][0], 0, sizeof(ull)*l);
    for (int i=m-1; i>=0; --i) set_bit(s[B[i]-'a'], m-1-i);
    for (int k=0; k<n; ++k) {
        memset(&d[0], 0, sizeof(ull)*l);
        for (int i=m-1; i>=0; --i) if (A[k] == B[i]) { set_bit(d, m-1-i); break; }
        for (int i=n-1; i>=0; --i) {
            ull sc = 1, mc = 0;
            for (int j=0; j<l; ++j) {
                ull x = s[A[(k+i)%n]-'a'][j]|d[j];
                ull t = (d[j] << 1)|sc;
                sc = d[j] >> 63;
                ull tt = x;
                mc = sub(tt, mc) + sub(tt, t);
                d[j] = x&(x^tt);
            }
        }
        int ret = 0;
        for (int i=m-1; i>=0; --i) ret += get_bit(d, m-1-i);
        ans=max(ans, ret);
    }
    cout << ans << endl;
}

Compilation message

rowords.cpp: In function 'int main()':
rowords.cpp:11:31: warning: operation on 'tt' may be undefined [-Wsequence-point]
   11 | #define sub(a, b) ((a-b>a)? (a-=b, 1) : (a-=b, 0))
......
   29 |                 mc = sub(tt, mc) + sub(tt, t);
      |                          ~~~~~~
rowords.cpp:29:22: note: in expansion of macro 'sub'
   29 |                 mc = sub(tt, mc) + sub(tt, t);
      |                      ^~~
rowords.cpp:38:56: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   38 |     for (int i=m-1; i>=0; --i) set_bit(s[B[i]-'a'], m-1-i);
      |                                                     ~~~^~
rowords.cpp:9:28: note: in definition of macro 'set_bit'
    9 | #define set_bit(bs, i) (bs[i>>6] |= 1llu << (i&63))
      |                            ^
rowords.cpp:38:56: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   38 |     for (int i=m-1; i>=0; --i) set_bit(s[B[i]-'a'], m-1-i);
      |                                                     ~~~^~
rowords.cpp:9:46: note: in definition of macro 'set_bit'
    9 | #define set_bit(bs, i) (bs[i>>6] |= 1llu << (i&63))
      |                                              ^
rowords.cpp:41:70: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   41 |         for (int i=m-1; i>=0; --i) if (A[k] == B[i]) { set_bit(d, m-1-i); break; }
      |                                                                   ~~~^~
rowords.cpp:9:28: note: in definition of macro 'set_bit'
    9 | #define set_bit(bs, i) (bs[i>>6] |= 1llu << (i&63))
      |                            ^
rowords.cpp:41:70: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   41 |         for (int i=m-1; i>=0; --i) if (A[k] == B[i]) { set_bit(d, m-1-i); break; }
      |                                                                   ~~~^~
rowords.cpp:9:46: note: in definition of macro 'set_bit'
    9 | #define set_bit(bs, i) (bs[i>>6] |= 1llu << (i&63))
      |                                              ^
rowords.cpp:11:31: warning: operation on 'tt' may be undefined [-Wsequence-point]
   11 | #define sub(a, b) ((a-b>a)? (a-=b, 1) : (a-=b, 0))
......
   49 |                 mc = sub(tt, mc) + sub(tt, t);
      |                          ~~~~~~
rowords.cpp:49:22: note: in expansion of macro 'sub'
   49 |                 mc = sub(tt, mc) + sub(tt, t);
      |                      ^~~
rowords.cpp:54:57: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   54 |         for (int i=m-1; i>=0; --i) ret += get_bit(d, m-1-i);
      |                                                      ~~~^~
rowords.cpp:10:29: note: in definition of macro 'get_bit'
   10 | #define get_bit(bs, i) ((bs[i>>6] >> (i&63))&1)
      |                             ^
rowords.cpp:54:57: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   54 |         for (int i=m-1; i>=0; --i) ret += get_bit(d, m-1-i);
      |                                                      ~~~^~
rowords.cpp:10:39: note: in definition of macro 'get_bit'
   10 | #define get_bit(bs, i) ((bs[i>>6] >> (i&63))&1)
      |                                       ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 18 ms 296 KB Output is correct
7 Correct 99 ms 284 KB Output is correct
8 Incorrect 106 ms 212 KB Output isn't correct
9 Incorrect 110 ms 212 KB Output isn't correct
10 Correct 97 ms 212 KB Output is correct
11 Correct 134 ms 284 KB Output is correct
12 Correct 149 ms 284 KB Output is correct
13 Correct 152 ms 212 KB Output is correct
14 Correct 137 ms 284 KB Output is correct
15 Incorrect 172 ms 284 KB Output isn't correct
16 Correct 114 ms 288 KB Output is correct
17 Incorrect 127 ms 212 KB Output isn't correct
18 Correct 189 ms 212 KB Output is correct
19 Correct 100 ms 284 KB Output is correct
20 Incorrect 152 ms 284 KB Output isn't correct
21 Correct 65 ms 292 KB Output is correct
22 Correct 102 ms 280 KB Output is correct
23 Correct 129 ms 212 KB Output is correct
24 Incorrect 155 ms 284 KB Output isn't correct
25 Incorrect 206 ms 284 KB Output isn't correct