QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21000#2492. Hash FunctionMacesutedTL 1707ms3716kbC++144.1kb2022-02-23 17:50:172022-05-03 12:11:30

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-03 12:11:30]
  • 评测
  • 测评结果:TL
  • 用时:1707ms
  • 内存:3716kb
  • [2022-02-23 17:50:17]
  • 提交

answer

/**
 * @file 2492.cpp
 * @author Macesuted ([email protected])
 * @date 2022-02-23
 *
 * @copyright Copyright (c) 2022
 * @brief
 *      Time Limit: 3S  Memory Limit: 64M
 *
 */

#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple

namespace io {
#define SIZE (1 << 20)
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55];
int f, qr;
inline void flush(void) { return fwrite(obuf, 1, oS - obuf, stdout), oS = obuf, void(); }
inline char getch(void) {
    return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++);
}
void putch(char x) {
    *oS++ = x;
    if (oS == oT) flush();
    return;
}
string getstr(void) {
    string s = "";
    char c = getch();
    while (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == EOF) c = getch();
    while (!(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == EOF)) s.push_back(c), c = getch();
    return s;
}
void putstr(string str, int begin = 0, int end = -1) {
    if (end == -1) end = str.size();
    for (int i = begin; i < end; i++) putch(str[i]);
    return;
}
template <typename T>
T read() {
    T x = 0;
    for (f = 1, c = getch(); c < '0' || c > '9'; c = getch())
        if (c == '-') f = -1;
    for (x = 0; c <= '9' && c >= '0'; c = getch()) x = x * 10 + (c & 15);
    return x * f;
}
template <typename T>
void write(const T& t) {
    T x = t;
    if (!x) putch('0');
    if (x < 0) putch('-'), x = -x;
    while (x) qu[++qr] = x % 10 + '0', x /= 10;
    while (qr) putch(qu[qr--]);
    return;
}
struct Flusher_ {
    ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io::getch;
using io::getstr;
using io::putch;
using io::putstr;
using io::read;
using io::write;

bool mem1;

#define maxn 17

int n;
long long maxS, mod;
vector<int> S1, S2, S3;
map<long long, long long> record;

long long R(long long S) { return (S >> 1) | ((long long)(S & 1) << (2 * n - 1)); }
long long calcB(long long A) {
    long long B = 0;
    for (int t = 0; t < n; t++) B |= (long long)((A >> t & 1) ^ (A >> (2 * t + 1) & 1)) << t;
    for (int t = n; t < 2 * n; t++) B |= (long long)((A >> t & 1) ^ (A >> (4 * n - 2 * t - 2) & 1)) << t;
    return B;
}

void solve(void) {
    n = read<int>();
    long long H = read<long long>(), max1S = (1LL << n) - 1, max2S = max1S << n;
    maxS = (1LL << (2 * n)) - 1, mod = (1LL << (2 * n - 1)) - 1;
    for (int i = 0; i < 2 * n; i++) {
        long long S = calcB(1LL << i);
        S = S ^ R(S);
        if (!S) continue;
        vector<int> pos;
        for (int j = 0; j < 2 * n; j++)
            if (S >> j & 1) pos.push_back(j);
        if (pos.back() < n)
            S1.push_back(i);
        else if (pos.front() >= n)
            S2.push_back(i);
        else
            S3.push_back(i);
    }
    int S1z = S1.size(), S2z = S2.size(), S3z = S3.size();
    for (int i = 0; i < (1 << S3z); i++) {
        long long A_ = 0;
        for (int t = 0; t < S3z; t++) A_ |= (long long)(i >> t & 1) << S3[t];
        for (int j = 0; j < (1 << S1z); j++) {
            long long A = A_;
            for (int t = 0; t < S1z; t++) A |= (long long)(j >> t & 1) << S1[t];
            long long B = calcB(A), C = (B ^ R(B)) & max1S;
            record[(H + mod - (239 * A + 153 * C) % mod) % mod] = A;
        }
        for (int j = 0; j < (1 << S2z); j++) {
            long long A = 0;
            for (int t = 0; t < S2z; t++) A |= (long long)(j >> t & 1) << S2[t];
            long long B = calcB(A | A_), C = (B ^ R(B)) & max2S;
            auto p = record.find((239 * A + 153 * C) % mod);
            if (p != record.end()) return write(p->second | A), putch('\n');
        }
        record.clear();
    }
    return putstr("No Solution!\n");
}

bool mem2;

int main() {
#ifdef MACESUTED
    cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

    int _ = 1;
    while (_--) solve();

#ifdef MACESUTED
    cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl;
#endif
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3584kb

input:

4 83

output:

13

result:

ok good solution

Test #2:

score: 0
Accepted
time: 5ms
memory: 3644kb

input:

10 497091

output:

153014

result:

ok good solution

Test #3:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

4 55

output:

73

result:

ok good solution

Test #4:

score: 0
Accepted
time: 1194ms
memory: 3560kb

input:

15 444650548

output:

377677832

result:

ok good solution

Test #5:

score: 0
Accepted
time: 470ms
memory: 3568kb

input:

14 114355996

output:

119238393

result:

ok good solution

Test #6:

score: 0
Accepted
time: 3ms
memory: 3640kb

input:

16 0

output:

0

result:

ok good solution

Test #7:

score: 0
Accepted
time: 3ms
memory: 3560kb

input:

3 22

output:

8

result:

ok good solution

Test #8:

score: 0
Accepted
time: 4ms
memory: 3612kb

input:

8 8319

output:

47842

result:

ok good solution

Test #9:

score: 0
Accepted
time: 100ms
memory: 3660kb

input:

12 7629490

output:

11766463

result:

ok good solution

Test #10:

score: 0
Accepted
time: 3ms
memory: 3664kb

input:

2 2

output:

3

result:

ok good solution

Test #11:

score: 0
Accepted
time: 2ms
memory: 3708kb

input:

16 0

output:

0

result:

ok good solution

Test #12:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

16 0

output:

0

result:

ok good solution

Test #13:

score: 0
Accepted
time: 3ms
memory: 3568kb

input:

16 0

output:

0

result:

ok good solution

Test #14:

score: 0
Accepted
time: 17ms
memory: 3492kb

input:

11 1086647

output:

1875946

result:

ok good solution

Test #15:

score: 0
Accepted
time: 5ms
memory: 3588kb

input:

11 188671

output:

393405

result:

ok good solution

Test #16:

score: 0
Accepted
time: 29ms
memory: 3704kb

input:

11 2028522

output:

3482225

result:

ok good solution

Test #17:

score: 0
Accepted
time: 233ms
memory: 3560kb

input:

13 23601796

output:

40518521

result:

ok good solution

Test #18:

score: 0
Accepted
time: 4ms
memory: 3536kb

input:

8 29405

output:

39139

result:

ok good solution

Test #19:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

7 2218

output:

3174

result:

ok good solution

Test #20:

score: 0
Accepted
time: 2ms
memory: 3608kb

input:

7 432

output:

662

result:

ok good solution

Test #21:

score: 0
Accepted
time: 9ms
memory: 3504kb

input:

11 899191

output:

570326

result:

ok good solution

Test #22:

score: 0
Accepted
time: 3ms
memory: 3696kb

input:

5 494

output:

281

result:

ok good solution

Test #23:

score: 0
Accepted
time: 4ms
memory: 3660kb

input:

8 13862

output:

51543

result:

ok good solution

Test #24:

score: 0
Accepted
time: 27ms
memory: 3588kb

input:

11 899027

output:

3346232

result:

ok good solution

Test #25:

score: 0
Accepted
time: 4ms
memory: 3620kb

input:

8 7446

output:

49853

result:

ok good solution

Test #26:

score: 0
Accepted
time: 3ms
memory: 3644kb

input:

3 12

output:

6

result:

ok good solution

Test #27:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

8 6258

output:

18666

result:

ok good solution

Test #28:

score: 0
Accepted
time: 1386ms
memory: 3660kb

input:

15 191474555

output:

411455767

result:

ok good solution

Test #29:

score: 0
Accepted
time: 2ms
memory: 3560kb

input:

3 17

output:

20

result:

ok good solution

Test #30:

score: 0
Accepted
time: 1303ms
memory: 3588kb

input:

15 161474861

output:

318717104

result:

ok good solution

Test #31:

score: 0
Accepted
time: 4ms
memory: 3716kb

input:

10 180816

output:

81147

result:

ok good solution

Test #32:

score: 0
Accepted
time: 2ms
memory: 3708kb

input:

4 116

output:

81

result:

ok good solution

Test #33:

score: 0
Accepted
time: 1707ms
memory: 3712kb

input:

16 1196684556

output:

567748713

result:

ok good solution

Test #34:

score: 0
Accepted
time: 1149ms
memory: 3712kb

input:

16 1087033358

output:

458416341

result:

ok good solution

Test #35:

score: -100
Time Limit Exceeded

input:

16 2112546660

output:


result: