QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#835696#9922. Mah-jongucup-team045#WA 2462ms7180kbC++201.9kb2024-12-28 14:00:352024-12-28 14:00:35

Judging History

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

  • [2024-12-28 14:00:35]
  • 评测
  • 测评结果:WA
  • 用时:2462ms
  • 内存:7180kb
  • [2024-12-28 14:00:35]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
int pos[7000];
vector<int> match[7000];

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int pow3[10];
    pow3[0] = 1;
    for(int i = 1; i < 10; i++) pow3[i] = pow3[i - 1] * 3;
    for(int i = 0; i < pow3[8]; i++){
        for(int j = 0; j < pow3[8]; j++){
            int cnt[8];
            bool ok = true;
            for(int k = 0; k < 8; k++){
                int t1 = (i % pow3[k + 1]) / pow3[k];
                int t2 = (j % pow3[k + 1]) / pow3[k];
                cnt[k] = (t1 - t2 + 3) % 3;
            }
            for(int i = 0; i + 2 < 8; i++){
                if (cnt[i] < 0){
                    ok = false;
                    break;
                }
                while(cnt[i] > 0){
                    cnt[i] -= 1;
                    cnt[i + 1] -= 1;
                    cnt[i + 2] -= 1;
                }
            }
            for(int i = 0; i < 8; i++){
                if (cnt[i] != 0){
                    ok = false;
                    break;
                }
            }
            if (ok){
                match[i].push_back(j);
            }
        }
    }

    int T;
    cin >> T;
    while(T--){
        for(int i = 0; i < pow3[8]; i++) pos[i] = 0;
        int n;
        cin >> n;
        int cnt[8]{};
        pos[0] += 1;
        int val = 0;
        LL ans = 0;
        for(int i = 1; i <= n; i++){
            int x;
            cin >> x;
            x--;
            val -= cnt[x] * pow3[x];
            cnt[x] = (cnt[x] + 1) % 3;
            val += cnt[x] * pow3[x];
            for(auto x : match[val]){
                ans += pos[x];
            }
            pos[val] += 1;
        }
        cout << ans << '\n';
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2443ms
memory: 7120kb

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: 2462ms
memory: 7180kb

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:

5694
7070
616
268
26028
778
1283
5018
46691
128864
1938
15082
32608
100853
23516
198
9423
15243
7779
1
8633
0
4479
1952
9346
0
11167
17750
1
54471
6711
20965
2994
6771
3317
1301
283
620
8320
95598
18744
2774
103
9598
138112
201
1354
16983
1470
2685
2877
1160
35786
57
81
1901
12155
3339
569
54260
345...

result:

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