QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#524132 | #7880. Streak Manipulation | PonyHex | WA | 1ms | 8060kb | C++14 | 3.2kb | 2024-08-19 11:00:42 | 2024-08-19 11:00:43 |
Judging History
answer
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define ll long long
#define lc u<<1
#define rc u<<1|1
#define X first
#define Y second
const int N = 2e5 + 5;
const int M = 5005;
const ll maxm = 1e18 + 5;
ll a[N], f[N];
ll dp[N][6][2];//在i的位置,放了j串,当前字符是否为第j段串的结尾
string str;
ll n, m, k;
bool check(ll len) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 5; j++) {
dp[i][j][0] = maxm;
dp[i][j][1] = maxm;
}
}
for (int i = 0; i <= n; i++) {
dp[i][0][1] = 0;//1表示做结
dp[i][0][0] = 0;
}
//我怎么想不到怎么状态转移,
//en,一段串的结束,可以向前找到上一段串的结束
//但是,我们很快就会发现,我们找到的pos并不准确
//因为两段串间并不一定只隔1个0
//所以我们需要状态的继承,也就是说我们始终记录以当前节点作为结尾的第k段的代价
//如果我们尝试更新一个做结的位置,那么他需要向前去找二分长度位置的做结的转移过来
//所有的位置的做结的状态都应继承上一个位置做结的状态
for (int i = 1; i <= n; i++) {//枚举位置
for (int j = 1; j <= k; j++) {//枚举放置的串的个数
//dp[i][j][0]不是我怎么不知道怎么更新你
dp[i][j][1] = min(dp[i - 1][j][1], dp[i][j][1]);//继承
if ((i - (len+1)) >= 0) {//从i到len,
if (str[i] == '0') {
dp[i][j][1] = min(dp[i][j][1], dp[i - (len + 1)][j - 1][1] + f[i] - f[i - (len + 1)]);
}
}
}
}
if (dp[n][k][1] <= m)return true;
return false;
}
void solve()
{
//dp还是比较弱,唉,状态设置想不到,状态转移的思维也不行
//check的时候,状态设置成,前i个字符,放置了j个长度为mid的,标记是否位于结尾,内存操作数
//感觉是一种比较抽象的dp,其实就是一维放置了当前的状态
//这样的之前也不是没见过,但就是不好想,不知道怎么设置状态,也没考虑好怎么转移
cin >> n >> m >> k;
cin >> str;
str = "~" + str;
for (int i = 1; i <= n; i++) {
if (str[i] == '0') {
a[i] = 1; f[i] = 1;
}
else
a[i] = f[i] = 0;
}
f[0] = 0;
for (int i = 1; i <= n; i++)f[i] += f[i - 1];
ll l = 0, r = n;
while (l + 1 < r) {
ll mid = (l + r) >> 1;
bool f = check(mid);
if (f) {//当前mid合法,还能更大
l = mid;
}
else {
r = mid;
}
}
if (l == 0)cout << -1 << endl;
else
cout << l+1 << endl;
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
//std::cin >> T;
while (T--)
solve();
return 0;
}
ll ksm(ll a, ll b) {
ll base = a;
ll ans = 1;
while (b) {
if (b & 1)ans *= base;
base *= base;
b >>= 1;
}
return ans;
}
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7676kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7668kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5696kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 8060kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
97
result:
wrong answer 1st numbers differ - expected: '99', found: '97'