QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#876293 | #9922. Mah-jong | CirnoNine | TL | 4ms | 3840kb | C++23 | 2.3kb | 2025-01-30 19:44:12 | 2025-01-30 19:44:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define int long long
#define pii pair<int,int>
struct P {
array<int,8> c;
P() {
for (auto &x : c) {
x = 0;
}
}
int val() {
int ans = 0;
int k = 1;
for (int i = 0; i < 8; i++) {
ans += k*c[i];
k*=3;
}
return ans;
}
void clear() {
fill(c.begin(), c.end(), 0);
}
bool exist() {
for (auto x : c) {
if (x < 0) return 0;
}
return 1;
}
P change() {
P tmp;
for (int i = 0; i < 8; i++) {
tmp.c[i] = c[i]%3;
}
return tmp;
}
P operator-(P &t) {
P tmp;
for (int i = 0; i < 8; i++) {
tmp.c[i] = c[i]-t.c[i];
}
return tmp;
}
const bool operator<(P &t) {
return c < t.c;
}
};
vector<P> vt;
void init() {
P p;
for (int i = 0; i < 729; i++) {
int tmp = i;
p.clear();
for (int j = 0; j < 6; j++) {
int q = tmp%3;
for (int k = j; k < j+3; k++) {
p.c[k]+=q;
}
tmp/=3;
}
// for (auto x : p.c) {
// cout << x << " ";
// }
// cout << endl;
vt.push_back(p);
}
}
vector<int> mp(6561,0);
void solve() {
int n;
cin >> n;
vector<int> a(n+9);
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i]--;
}
int ans = 0;
for (auto p2 : vt) {
fill(mp.begin(),mp.end(),0);
P p,p0,p1;
mp[p.val()]++;
int l = 1,r;
for (r = 1; r <= n; r++) {
p.c[a[r]]++;p1.c[a[r]]++;
while (l < r && (p-p2).exist()) {
p.c[a[l]]--;
p0.c[a[l]]++;
mp[p0.change().val()]++;
l++;
}
if ((p1-p2).exist()) {
ans += mp[(p1-p2).change().val()];
}
}
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
init();
int t = 1;
cin >> t;
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 3840kb
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
Time Limit Exceeded
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...