QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768579#7880. Streak ManipulationliliwaWA 1ms5876kbC++231.7kb2024-11-21 12:36:102024-11-21 12:36:11

Judging History

你现在查看的是最新测评结果

  • [2024-11-21 12:36:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5876kb
  • [2024-11-21 12:36:10]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

#define x first
#define y second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define lep(i,a,b) for(int i=(a);i>=(b);i--)
#define sci(x) cin >> (x)
#define pli(x) cout << (x) << " ";
#define pll(x) cout << (x) << '\n';
#define yes cout << "Yes" << '\n';
#define no cout << "No" << '\n';
#define ls u << 1
#define rs u << 1 | 1
//cout << "? " << << ' ';
//printf("case:%d %d\n", );

const int N = 1e6 + 10;
//const ll p = 1e9 + 7;
ll n, m, k;

ll a[N], b[N], f[N][6][2], f1[N];
string s1, s2;

bool check(ll mid)
{
    rep(i, 0, n) rep(j, 0, k) f[i][j][0] = f[i][j][1] = 1e18; f[0][0][0] = 0;
    
    rep(i, 1, n) rep(j, 1, k)
    {
        if(s1[i] == '1')
        {
            f[i][j][0] = min(f[i][j][0], f[i - 1][j][0]);
            f[i][j][1] = min(f[i][j][1], f[i - 1][j][1]);
        }
        else
        {
            f[i][j][0] = min({f[i][j][0], f[i - 1][j][1], f[i - 1][j][0]});
            f[i][j][1] = min(f[i][j][1], f[i - 1][j][1] + 1);
        }
        
        if(i >= mid) f[i][j][1] = min(f[i][j][1], f[i - mid][j - 1][0] + f1[i] - f1[i - mid]);
    }
    
    return min(f[n][k][0], f[n][k][1]) <= m;
}

void solve()
{
    cin >> n >> m >> k >> s1; s1 = " " + s1;
    rep(i, 1, n) f1[i] = f1[i - 1] + (s1[i] == '0');
    
    ll l = 0, r = n + 1;
    while(l + 1 != r)
    {
        ll mid = l + r >> 1;
        if(check(mid)) l = mid; else r = mid;
    }
    if(l == 0) l = -1; pll(l)
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T; T = 1;
    //cin >> T;
    while (T--)
    {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5876kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5608kb

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5676kb

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 5612kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

96

result:

wrong answer 1st numbers differ - expected: '99', found: '96'