QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#844700#9922. Mah-jonghhoppitreeWA 2091ms172060kbC++232.1kb2025-01-06 10:13:152025-01-06 10:13:15

Judging History

This is the latest submission verdict.

  • [2025-01-06 10:13:15]
  • Judged
  • Verdict: WA
  • Time: 2091ms
  • Memory: 172060kb
  • [2025-01-06 10:13:15]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int a[N], d[9], c[9], tc[6561], f[N], sum[6561][6561];

signed main() {
    for (int i = 0; i < 6561; ++i) {
        for (int j = 0; j < 6561; ++j) {
            int ti = i, tj = j;
            for (int k = 1, pw = 1; k <= 8; ++k, pw *= 3) {
                int x = (ti % 3 + tj % 3) % 3;
                ti /= 3, tj /= 3;
                sum[i][j] += x * pw;
            }
        }
    }
    int T; scanf("%d", &T);
    while (T--) {
        int n; scanf("%d", &n);
        for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
        for (int i = 1; i <= n; ++i) {
            f[i] = f[i - 1];
            int now = f[i];
            for (int j = 1, pw = 1; j <= 8; ++j, pw *= 3) {
                int x = now % 3;
                now /= 3;
                if (j == a[i]) {
                    if (x != 2) f[i] += pw;
                    else f[i] -= pw + pw;
                }
            }
        }
        long long res = 0;
        for (int i = 0; i < 729; ++i) {
            fill(d + 1, d + 9, 0), fill(c + 1, c + 9, 0);
            int ti = i;
            for (int j = 1; j <= 6; ++j) {
                int x = ti % 3;
                ti /= 3;
                d[j] += x, d[j + 1] += x, d[j + 2] += x;
            }
            int sta = 0, ok = count(d + 1, d + 9, 0), r = 1;
            for (int j = 1, pw = 1; j <= 8; ++j, pw *= 3) {
                sta += d[j] * pw;
            }
            ok += (++c[a[r]] == d[a[r]]);
            while (r < n && ok < 8) {
                ++r, ok += (++c[a[r]] == d[a[r]]);
            }
            if (ok < 8) continue;
            int l = 1;
            memset(tc, 0, sizeof(tc));
            auto ins = [&](int x) {
                ++tc[sum[f[x - 1]][sta]];
            };
            ins(l);
            while (r <= n) {
                while (l < r && c[a[l]] != d[a[l]]) --c[a[l]], ++l, ins(l);
                res += tc[f[r]], ++r;
                if (r <= n) ++c[a[r]];
            }
        }
        printf("%lld\n", res);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 997ms
memory: 172060kb

input:

5
4
1 1 1 1
6
1 2 3 1 2 3
7
6 5 8 7 6 3 2
8
1 2 1 2 1 2 1 3
9
2 2 4 4 1 1 1 3 3

output:

2
5
1
3
2

result:

ok 5 number(s): "2 5 1 3 2"

Test #2:

score: -100
Wrong Answer
time: 2091ms
memory: 171980kb

input:

100
992
8 1 8 1 2 3 6 6 1 3 1 8 7 7 4 7 7 1 6 6 4 8 3 7 3 5 1 4 4 7 5 7 5 7 4 3 7 5 2 8 7 1 6 3 6 2 4 3 2 3 1 6 3 1 3 2 6 6 7 4 6 1 1 4 6 4 7 7 8 5 6 4 1 5 4 8 2 4 4 2 1 3 5 7 6 8 3 7 6 6 5 6 4 2 5 4 3 7 3 5 5 3 3 2 7 8 2 7 2 4 4 3 4 1 1 3 5 5 4 6 3 3 3 2 6 1 2 6 4 8 8 6 6 8 7 3 1 1 8 8 7 2 5 6 3 5 ...

output:

50218
60100
4878
1827
238662
5963
10481
45075
432154
1215202
16711
137789
297450
955422
215652
1075
85976
138441
68431
1
77480
0
38227
16034
84666
0
98211
160273
1
509626
57599
195340
25447
60421
28283
10911
1906
4159
73313
902837
171411
23224
436
86436
1298480
1173
11431
154312
11176
22492
24764
91...

result:

wrong answer 1st numbers differ - expected: '51699', found: '50218'