QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#501343#7880. Streak ManipulationDecadeWA 1ms3836kbC++172.5kb2024-08-02 16:58:392024-08-02 16:58:40

Judging History

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

  • [2024-08-02 16:58:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3836kb
  • [2024-08-02 16:58:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
mt19937 rng;
uniform_int_distribution <ull> dist(0,1ull<<63);
//#define mp make_pair
inline void print(__int128 x){//输出模板 
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
inline int read()
{
    int X = 0;
    bool flag = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            flag = 0;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        X = (X << 1) + (X << 3) + ch - '0';
        ch = getchar();
    }
    if (flag)
        return X;
    return ~(X - 1);
}
const ll mod = 1e9 + 7,INF = 0x3f3f3f3f;
ll qpow(ll a, ll b)
{
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int N = 200010,M = 1000010;

string s;
int f[N][10][2],sum[N];
int n,m,k;

bool check(int x)
{
    for(int i=0;i<=n;i++)for(int j=1;j<=k;j++) f[i][j][1] = f[i][j][0] = INF;
    f[0][0][0] = 0;
    for(int i=1;i<=n;i++) 
    {
        if(s[i]=='1') f[i][0][1] = 0;
        else f[i][0][0] = 0,f[i][0][1] = 1;
    }
    int tmp[10];
    for(int i=0;i<=k;i++) tmp[i] = INF;
    int res = INF;
    for(int i=x;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            tmp[j-1] = min(tmp[j-1],f[i-x][j-1][0]-sum[i-x]);
            if(s[i]=='1') f[i][j][1] = min(f[i][j][1],sum[i]+tmp[j-1]);
            else 
            {
                f[i][j][1] = min(f[i][j][1],sum[i]+tmp[j-1]);
                f[i][j][0] = min(f[i-1][j][0],f[i-1][j][1]);
            }
        }
        res = min({res,f[i][k][0],f[i][k][1]});
    }
        
    return res<=m;
}

void solve()
{
    cin>>n>>m>>k;
    cin>>s;
    s = ' '+s;
    for(int i=1;i<=n;i++) sum[i] = sum[i-1]+(s[i]=='0');
    int l = 0,r = n;
    while(r>l)
    {
        int mid = l+r+1>>1;
        if(check(mid)) l = mid;
        else r = mid-1; 
    }
    if(!l) cout<<-1<<'\n';
    else cout<<l<<'\n';
}

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

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

90

result:

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