QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#836193#9922. Mah-jongucup-team296#RE 1ms3792kbC++202.3kb2024-12-28 17:17:562024-12-28 17:17:56

Judging History

This is the latest submission verdict.

  • [2024-12-28 17:17:56]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 3792kb
  • [2024-12-28 17:17:56]
  • Submitted

answer

#include <bits/stdc++.h>
#define long long long int
#define DEBUG
using namespace std;

// @author: pashka

vector<int> a(8);
set<vector<int>> s;

void bt(int i) {
    if (i == 8) {
        s.insert(a);
        return;
    }
    if (i + 3 <= 8) {
        for (int x = 1; x < 3; x++) {
            for (int j = 0; j < 3; j++) {
                a[i + j] += x;
            }
            bt(i + 1);
            for (int j = 0; j < 3; j++) {
                a[i + j] -= x;
            }
        }
    }
    bt(i + 1);
}


struct test {
    void solve() {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            a[i]--;
        }
        vector<int> p3(9);
        p3[0] = 1;
        for (int i = 1; i < 9; i++) p3[i] = p3[i - 1] * 3;
        vector<vector<int>> p(p3[8]);
        vector<int> cc(8);
        for (int i = 0; i < n; i++) {
            cc[a[i]]++;
            int cs = 0;
            for (int j = 0; j < 8; j++) {
                cs += p3[j] * (cc[j] % 3);
            }
            p[cs].push_back(i + 1);
        }

        long res = 0;
        for (auto &c : s) {
            vector<int> b(8);
            int bd = 0;
            for (int i = 0; i < 8; i++) {
                if (b[i] < c[i]) bd++;
            }
            int r = 0;
            auto cc = c;
            for (int l = 0; l < n; l++) {
                while ((r <= l || bd > 0) && r < n) {
                    int x = a[r++];
                    b[x]++;
                    if (b[x] == c[x]) bd--;
                }

                if (bd > 0) break;
                int cs = 0;
                for (int i = 0; i < 8; i++) {
                    cs += cc[i] * p3[i];
                }

                auto &z = p[cs];
                res += z.size() - (lower_bound(z.begin(), z.end(), r) - z.begin());

                {
                    int x = a[l];
                    b[x]--;
                    if (b[x] == c[x] - 1) bd++;
                }
                cc[a[l]]++;
                cc[a[l]] %= 3;
            }
        }
        cout << res << "\n";
    }
};

int main() {
    ios::sync_with_stdio(false);


    bt(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        test().solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3792kb

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
Runtime Error

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:


result: