QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#835768 | #9922. Mah-jong | ucup-team045# | RE | 1ms | 3900kb | C++20 | 2.6kb | 2024-12-28 14:33:40 | 2024-12-28 14:33:41 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<array>
#include<unordered_map>
using namespace std;
using LL = long long;
int pos[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;
vector<pair<array<int, 8>, int> > state;
array<int, 8> cnt{};
auto dfs = [&](auto &&dfs, int u){
if (u == 6){
int val = 0;
for(int i = 0; i < 8; i++){
val += pow3[i] * cnt[i];
}
state.push_back({cnt, val});
return;
}
for(int i = 0; i < 3; i++){
cnt[u] += i;
cnt[u + 1] += i;
cnt[u + 2] += i;
dfs(dfs, u + 1);
cnt[u] -= i;
cnt[u + 1] -= i;
cnt[u + 2] -= i;
}
};
dfs(dfs, 0);
int T;
cin >> T;
while(T--){
int n;
cin >> n;
vector<int> v(n + 1);
vector<array<int, 8> > pre(n + 1);
int cnt[8]{};
int val = 0;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++){
int x;
cin >> x;
x--;
a[i] = x;
val -= cnt[x] * pow3[x];
cnt[x] = (cnt[x] + 1) % 3;
val += cnt[x] * pow3[x];
v[i] = val;
pre[i] = pre[i - 1];
pre[i][x] += 1;
}
LL ans = 0;
for(auto &[c, delta] : state){
int pt = 0;
int need = 0;
for(int i = 0; i < 8; i++){
int k = (3 - c[i] % 3) % 3;
need += pow3[i] * k;
}
for(int i = 1; i <= n; i++){
int cur = (need % pow3[a[i] + 1]) / pow3[a[i]];
need -= cur * pow3[a[i]];
cur = (cur + 1) % 3;
need += cur * pow3[a[i]];
auto check = [&](){
for(int j = 0; j < 8; j++){
if (pre[i][j] - pre[pt][j] < c[j]){
return false;
}
}
return true;
};
while(check()){
pos[v[pt]] += 1;
pt++;
}
ans += pos[need];
}
for(int i = 0; i <= n; i++) pos[v[i]] = 0;
}
cout << ans - n << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3900kb
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 ...