QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#736401 | #9614. 分治 | hos_lyric# | 20 | 462ms | 12284kb | C++14 | 2.6kb | 2024-11-12 10:46:44 | 2024-11-12 10:46:46 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
constexpr int N = 128;
// n, mex, amari -> score
int dp[N + 1][N + 1][N + 1];
int main() {
memset(dp, ~0, sizeof(dp));
dp[1][0][1] = 0;
dp[1][1][0] = 1;
for (int n = 2; n <= N; ++n) {
auto check = [&](int n0, int n1) -> void {
vector<int> fs1(n1 + 1, -1);
for (int a1 = 0; a1 <= n1; ++a1) for (int b1 = 0; b1 <= n1; ++b1) {
chmax(fs1[b1], dp[n1][a1][b1]);
}
for (int a0 = 0; a0 <= n0; ++a0) for (int b0 = 0; b0 <= n0; ++b0) if (~dp[n0][a0][b0]) {
for (int b1 = 0; b1 <= n1; ++b1) if (~fs1[b1]) {
for (int a = a0; a <= a0 + b0 + b1; ++a) {
chmax(dp[n][a][b0 + b1 - (a - a0)], a + dp[n0][a0][b0] + fs1[b1]);
}
}
}
};
check(n/2, n - n/2);
if (n/2 != n - n/2) check(n - n/2, n/2);
}
for (int n = 1; n <= N; ++n) {
int mx = -1;
int am = -1, bm = -1;
for (int a = 0; a <= n; ++a) for (int b = 0; b <= n; ++b) {
if (chmax(mx, dp[n][a][b])) {
am = a;
bm = b;
}
}
cerr << n << " " << am << " " << bm << ": " << mx << endl;
}
char S[10];
for (; ~scanf("%s", S); ) {
int n = 0;
for (char *s = S; *s; ++s) (n <<= 1) |= (*s - '0');
int ans = 0;
for (int a = 0; a <= n; ++a) for (int b = 0; b <= n; ++b) chmax(ans, dp[n][a][b]);
printf("%d\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 453ms
memory: 12284kb
input:
110
output:
15
result:
ok 1 number(s): "15"
Test #2:
score: 10
Accepted
time: 462ms
memory: 12212kb
input:
101
output:
12
result:
ok 1 number(s): "12"
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #3:
score: 10
Accepted
time: 459ms
memory: 12284kb
input:
111110
output:
198
result:
ok 1 number(s): "198"
Test #4:
score: 10
Accepted
time: 458ms
memory: 12212kb
input:
1001001
output:
253
result:
ok 1 number(s): "253"
Subtask #3:
score: 0
Runtime Error
Dependency #2:
100%
Accepted
Test #5:
score: 0
Runtime Error
input:
10100011000100111
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #7:
score: 0
Runtime Error
input:
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%