QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107415 | #6185. Best Problem | zhoukangyang | ML | 2ms | 3512kb | C++17 | 1.4kb | 2023-05-21 11:47:59 | 2023-05-21 11:48:01 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define ll long long
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a))
#define eb emplace_back
#define uint unsigned int
using namespace std;
const int N = 1e6 + 7;
char s[N];
int n, a[N];
map < vi, int > MP;
int slv(vi a) {
while(sz(a) && !a[0]) a.erase(a.begin());
if(!sz(a)) return 0;
int n = sz(a) - 1;
a[n] = 0;
L(i, 1, n - 1)
if(a[i] > 1 && a[i + 1] == 0) {
vi A, B;
L(j, 0, i) {
A.emplace_back(a[j]);
}
L(j, i + 1, n) {
B.emplace_back(a[j]);
}
return slv(A) + slv(B);
}
if(MP.count(a)) return MP[a];
int ans = 0;
vi b = a;
R(i, n - 1, 1)
if(b[i - 1] > 0 && b[i] == 1) {
b[i] = 1e9, ans = slv(b);
b = a, --b[i - 1], ++b[i + 1];
ans = max(ans, slv(b) + 1);
return MP[a] = ans;
}
return MP[a] = 0;
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> (s + 1);
n = strlen(s + 1);
int cur = 0;
L(i, 1, n) {
if(s[i] == '1') {
++cur;
} else {
a[cur] += 1;
}
}
vi T(cur + 1);
L(i, 0, cur) T[i] = a[i];
cout << slv(T) << '\n';
return 0;
}
/*
0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3380kb
input:
10100010011001011111
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3512kb
input:
0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010
output:
58
result:
ok 1 number(s): "58"
Test #3:
score: -100
Memory Limit Exceeded
input:
100011000011001011010100111110011001000110111101101001100000110101101001101111100101110001101101000001001011011111001100111010101111001110000110001100101100101001001110000111100001100110000101111110001010101100100110010001110011101011110011101111000111010111100110100011110000011111110000111110111110...