QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#631682 | #517. Sequential Yahtzee | chuchu# | WA | 124ms | 3856kb | C++20 | 3.3kb | 2024-10-12 09:38:47 | 2024-10-12 09:38:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
void solve() {
int n; cin >> n;
vector<int> a(n); for(auto& x : a) cin >> x;
vector<vector<int>> dp(13, vector<int>(n+1, -inf));
auto score = [&] (int cat, vector<int> cand) {
sort(cand.begin(), cand.end());
int sum = accumulate(cand.begin(), cand.end(), 0);
if (cat <= 6) {
int ct = 0;
for (auto x : cand)
if (x == cat) ct++;
return ct * cat;
}
if (cat == 7) {
for (int i = 0; i < 3; ++i) {
if (cand[i] == cand[i+2]) return sum;
}
return 0;
}
if (cat == 8) {
for (int i = 0; i < 2; ++i) {
if (cand[i] == cand[i+3]) return sum;
}
return 0;
}
if (cat == 9) {
if (cand[0] == cand[2] && cand[2] != cand[3] && cand[3] == cand[4]) return 25;
if (cand[0] == cand[1] && cand[1] != cand[2] && cand[2] == cand[4]) return 25;
return 0;
}
if (cat == 10) {
for (int i = 0; i < 2; ++i) {
int tmp = cand[i];
for (int j = i+1; j < i+5; ++j) {
if (j == i+4) return 30;
if (cand[j] != tmp + 1) break;
tmp++;
}
}
return 0;
}
if (cat == 11) {
int tmp = cand[0];
for (int j = 1; j < 6; ++j) {
if (j == 5) return 40;
if (cand[j] != tmp+1) break;
tmp++;
}
return 0;
}
if (cat == 12) {
return sum;
}
if (cat == 13) {
if (cand[0] == cand[4])
return 50;
return 0;
}
assert(false);
return 0;
};
for (int cat = 12; cat >= 0; --cat) {
for (int i = 0; i < n-4; ++i) {
vector<int> cand(5);
for (int j = 0; j < 5; ++j) cand[j] = a[i+j];
vector<int> sv = cand, sv2;
for (int j = 0; j < 32; ++j) {
cand = sv;
int tmp = i+5;
for (int k = 0; k < 5; ++k) {
if ((j >> k) & 1) {
if (tmp == n) break;
cand[k] = a[tmp++];
}
}
sv2 = cand;
for (int k = 0; k < 32; ++k) {
cand = sv2;
int tmp2 = tmp;
for (int l = 0; l < 5; ++l) {
if ((k >> l) & 1) {
if (tmp2 == n) break;
cand[l] = a[tmp2++];
}
}
dp[cat][i] = max(dp[cat][i], score(cat + 1, cand) + (cat == 12 ? 0 : dp[cat+1][tmp2]));
}
}
}
}
int ans = -inf;
for (int i = 0; i < n; ++i) {
ans = max(ans, dp[0][i]);
}
cout << ans << "\n";
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 31ms
memory: 3616kb
input:
65 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
70
result:
ok single line: '70'
Test #2:
score: 0
Accepted
time: 46ms
memory: 3664kb
input:
76 3 1 1 1 1 1 4 2 5 2 6 1 3 5 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 1 1 1 2 2 1 2 3 4 5 1 2 3 4 5 1 1 6 1 6 6 6 6 1 1 1 1 1 4
output:
340
result:
ok single line: '340'
Test #3:
score: 0
Accepted
time: 95ms
memory: 3664kb
input:
195 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
70
result:
ok single line: '70'
Test #4:
score: 0
Accepted
time: 30ms
memory: 3856kb
input:
65 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
70
result:
ok single line: '70'
Test #5:
score: 0
Accepted
time: 31ms
memory: 3820kb
input:
66 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
70
result:
ok single line: '70'
Test #6:
score: 0
Accepted
time: 122ms
memory: 3628kb
input:
195 2 2 2 2 2 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 1 1 1 1 1 2 2 2 2 2 4 4 4 4 4 1 1 1 1 1 2 2 2 2 2 5 5 5 5 5 1 1 1 1 1 2 2 2 2 2 6 6 6 6 6 1 1 1 1 1 2 2 2 2 2 6 6 6 6 6 1 1 1 1 1 2 2 2 2 2 6 6 6 6 6 1 2 3 4 5 2 3 4 5 6 1 2 1 2 1 1 1 1 1 1 2 2 2 2 2 1 6 4 ...
output:
340
result:
ok single line: '340'
Test #7:
score: 0
Accepted
time: 124ms
memory: 3604kb
input:
195 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 1 1 1 1 1 4 4 4 4 4 3 3 3 3 3 2 2 2 2 2 5 5 5 5 5 4 4 4 4 4 3 3 3 3 3 6 6 6 6 6 5 5 5 5 5 4 4 4 4 4 6 6 6 6 6 1 2 3 4 5 2 3 4 5 6 6 6 6 6 6 1 2 3 4 5 5 5 5 5 5 1 1 1 2 2 1 2 3 4 4 2 2 3 4 6 2 2 3 4 5 1 1 1 1 1 1 1 1 ...
output:
340
result:
ok single line: '340'
Test #8:
score: 0
Accepted
time: 84ms
memory: 3640kb
input:
135 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 1 2 2 2 3 1 2 3 4 5 6 6 6 5 5 6 6 6 6 6 1 2 3 4 5 5 5 5 5 5 1 1 1 2 2 1 2 3 4 4 2 2 3 4 6 2 2 3 4 5 1 1 1 1 1 1 1 1 1 1 6 5 4 3 2 1 1 1 1 1 1 1 1 1 1 6 6 6 6 6 6 6 5 5 4 6 5 4 3 2 6 6 6 6 6 1 2 3 4 5 1 1 1 2 3
output:
338
result:
ok single line: '338'
Test #9:
score: 0
Accepted
time: 48ms
memory: 3556kb
input:
85 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 6 6 6 6 6 6 6 6 6 6 1 1 1 2 2 1 2 3 4 4 1 2 3 4 5 6 6 6 6 6 1 1 1 1 1
output:
322
result:
ok single line: '322'
Test #10:
score: 0
Accepted
time: 47ms
memory: 3624kb
input:
77 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 1 1 1 2 2 2 2 2 2 3 1 1 1 1 3 2 2 4 4 5 1 1 3 3 6 6 5 4 1 2 3 4 5 4 3 2 1 2 2 3 3 4 1 1 2 2 3
output:
237
result:
ok single line: '237'
Test #11:
score: 0
Accepted
time: 112ms
memory: 3792kb
input:
180 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 1 1 2 2 3 6 5 4 3 2 4 2 1 3 6 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 3 4 5 6 1 3 4 5 6 1 3 4 5 6 1 4 5 6 1 2 4 5 6 1 2 4 5 6 1 2 5 6 1 2 3 5 6 1 2 3 5 6 1 ...
output:
294
result:
ok single line: '294'
Test #12:
score: 0
Accepted
time: 33ms
memory: 3856kb
input:
65 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 1 1 1 1 1 1 2 3 4 5 1 2 3 4 5 1 1 2 2 3 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2
output:
5
result:
ok single line: '5'
Test #13:
score: 0
Accepted
time: 52ms
memory: 3852kb
input:
68 1 3 2 1 5 2 6 1 6 1 4 1 6 3 4 5 1 6 1 4 3 6 4 3 5 5 3 3 1 4 4 6 5 2 6 4 6 4 5 4 6 4 6 3 3 4 1 6 4 5 1 4 1 2 3 1 5 4 3 2 4 6 3 6 6 5 2 1
output:
106
result:
ok single line: '106'
Test #14:
score: 0
Accepted
time: 60ms
memory: 3504kb
input:
78 5 1 4 2 6 6 6 6 1 4 6 1 5 3 5 3 4 5 4 4 5 6 4 3 5 6 5 5 5 1 2 3 4 3 6 4 5 2 3 1 3 2 6 4 5 6 2 6 2 1 5 3 3 1 6 6 1 6 3 2 3 4 2 2 5 6 2 6 3 3 1 4 5 5 2 4 3 2
output:
134
result:
ok single line: '134'
Test #15:
score: -100
Wrong Answer
time: 107ms
memory: 3792kb
input:
137 1 3 5 5 6 3 1 1 3 4 4 6 5 4 4 4 6 4 4 1 1 5 5 1 6 2 3 2 2 3 6 2 4 4 3 1 3 6 4 2 1 6 4 6 2 1 2 6 2 6 3 6 5 5 2 5 3 5 5 2 3 6 1 2 1 3 6 3 4 4 2 3 2 6 4 2 3 3 6 2 3 2 1 2 5 1 1 1 3 5 2 6 2 2 2 1 4 6 4 6 6 6 2 3 5 5 5 6 1 3 6 5 2 1 4 6 3 6 3 1 1 5 5 6 3 6 2 6 3 6 2 5 2 1 5 1 5
output:
225
result:
wrong answer 1st lines differ - expected: '239', found: '225'