QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#836208 | #9922. Mah-jong | ucup-team296# | TL | 1653ms | 4176kb | C++20 | 2.4kb | 2024-12-28 17:21:51 | 2024-12-28 17:21:56 |
Judging History
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 i = 0; i < 8; i++) cc[i] %= 3;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3848kb
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: 0
Accepted
time: 1653ms
memory: 4176kb
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:
51699 61486 5146 1960 241675 6274 11224 46170 435241 1219228 17198 139542 299436 960439 217729 1174 87401 141087 69813 1 78895 0 39510 16757 86551 0 100302 161956 3 512157 58619 196941 26116 61635 28879 11511 2061 4394 74620 907389 172780 23952 524 87857 1305332 1413 11784 156368 11746 23217 25189 9...
result:
ok 100 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
1 100000 7 6 3 7 1 2 5 2 4 5 3 2 6 2 2 2 5 6 5 8 6 2 1 8 2 2 1 1 4 8 2 6 4 1 8 6 6 7 8 4 4 5 4 7 8 6 2 3 3 7 5 7 1 1 3 5 2 8 5 6 3 6 2 3 3 8 4 5 7 8 1 5 6 1 3 4 5 7 1 5 4 4 4 6 6 4 2 3 5 2 7 3 5 8 7 1 5 4 5 4 1 5 8 7 2 2 8 2 4 3 5 7 6 6 1 6 6 3 1 1 3 1 7 8 1 7 3 7 8 3 6 3 5 7 5 1 8 7 4 7 5 4 8 1 3 4...
output:
555222305