QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497614#8783. Cherry PickingDecadeWA 1ms7428kbC++173.9kb2024-07-29 15:04:212024-07-29 15:04:22

Judging History

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

  • [2024-07-29 15:04:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7428kb
  • [2024-07-29 15:04:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> PII;
//#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 = 100010,M = 1000010;

int a[N],cnt[N],fa[N],vis[N];
string str;
vector<int> p[N];
multiset<int> S;

int find(int x)
{
    if(fa[x]!=x) return fa[x]=find(fa[x]);
    return fa[x];
}

void merge(int x,int y)
{
    x = find(x),y = find(y);
    if(x!=y)
    {
        fa[x] = y;
        if(cnt[y]&&cnt[x])
        {
            S.erase(S.find(cnt[y]));
            S.erase(S.find(cnt[x]));
        }
        cnt[y] += cnt[x];
        if(cnt[y]&&cnt[x])S.insert(cnt[y]);
    }
}

void solve()
{
    int n,k,mx = 0;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i],p[a[i]].push_back(i),mx = max(mx,a[i]);
    cin>>str;
    str = ' '+str;
    int ans = 0;
    for(int i=1;i<=n;i++) 
    {
        fa[i] = i;
        if(str[i]=='1') 
        {
            cnt[i] = 1;
            if(k==1) ans = 1;
            S.insert(1);
        }
    }
    for(int i=2;i<=n;i++)
    {
        if(str[i]==str[i-1]&&str[i]=='1')
            merge(i,i-1);
        if(cnt[find(i)]>=k) ans = 1;
    }
    int f = 0;
    for(int i=1;i<=mx;i++)
    {
        for(auto it:p[i])
        {
            if(str[it]=='0')
            {
                vis[it] = 1;
                if(it+1<=n)
                {
                    if(str[it+1]=='1') merge(it,it+1);
                    else if(vis[it+1]) merge(it,it+1);
                }
                if(it-1>=1)
                {
                    if(str[it-1]=='1') merge(it,it-1);
                    else if(vis[it-1]) merge(it,it-1);
                }
            }
            else
            {
                if(it+1<=n)
                {
                    if(str[it+1]=='1')
                    {
                        merge(it,it+1);
                        
                    } 
                    else if(vis[it+1]) merge(it,it+1);
                }
                if(it-1>=1)
                {
                    if(str[it-1]=='1')
                    {
                        merge(it,it-1);
                    } 
                    else if(vis[it-1]) merge(it,it-1);
                }
                // cout<<i<<endl;
                // for(auto it: S)
                // {
                //     cout<<it<<' ';
                // }
                // cout<<endl;
                S.erase(S.find(cnt[find(it)]));
                cnt[find(it)]--;
                if(cnt[find(it)])S.insert(cnt[find(it)]);
            }
        }
        if(S.size()&&*S.rbegin()>=k) ans = i+1;
        // cout<<i<<endl;
        // for(auto it: S)
        // {
        //     cout<<it<<' ';
        // }
        // cout<<endl;
    }
    cout<<ans<<'\n';
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2
1 2 3 4 5
01101

output:

2

result:

ok answer is '2'

Test #2:

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

input:

5 2
3 4 5 2 1
10101

output:

0

result:

ok answer is '0'

Test #3:

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

input:

1 1
1
1

output:

1

result:

ok answer is '1'

Test #4:

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

input:

1 1
1
0

output:

0

result:

ok answer is '0'

Test #5:

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

input:

5 3
8 3 5 2 7
10101

output:

5

result:

ok answer is '5'

Test #6:

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

input:

10 3
1 10 2 3 9 3 1 6 9 3
1100110001

output:

0

result:

ok answer is '0'

Test #7:

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

input:

10 1
6 7 2 10 8 4 4 9 7 9
0111011000

output:

10

result:

ok answer is '10'

Test #8:

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

input:

10 2
4 5 9 6 9 10 6 9 2 7
1100010100

output:

11

result:

wrong answer expected '9', found '11'