QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#667266#6841. Occupy the CitiesAlbert711WA 1ms3596kbC++202.0kb2024-10-22 21:58:242024-10-22 21:58:34

Judging History

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

  • [2024-10-22 21:58:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3596kb
  • [2024-10-22 21:58:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define db double
const int mod=1e9+7;
const int N=2e5+5;


void abt() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    s=' '+s;
    int jud=0;
    for(int i=1;i<=n;i++){
        if(s[i]=='0') jud=1;
    }
    if(!jud){
        cout<<0<<'\n';
        return ;
    }
    vector<int> idx(n+1);
    for(int i=1;i<=n;i++){
        if(s[i]=='1'){
            if(i-1>=1&&i+1<=n){
                if(s[i-1]=='1'){
                    idx[i+1]=1;
                }
                if(s[i+1]=='1'){
                    idx[i-1]=1;
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(idx[i]) s[i]='1';
    }
    vector<pair<int,int>>a;
    int cnt=1;
    for(int i=2;i<=n;i++){
        if(s[i]!=s[i-1]){
            int t=0;
            if(s[i]=='0') t=1;
            a.push_back({cnt,t});
            cnt=1;
        }else{
            cnt++;
        }
    }
    if(s[n]=='1'){
        a.push_back({cnt,1});
    }else{
        a.push_back({cnt,0});
    }
    int siz=a.size();
    for(int i=0;i<siz;i++){
        auto [t1,t2]=a[i];
        if(t2==1&&t1>1) continue;
        if(t2==1&&t1==1){
            if(i==0){
                a[i+1].first--;
            }else if(i==siz-1){
                a[i-1].first--;
            }else{
                if(a[i-1].first>=a[i+1].first){
                    a[i-1].first--;
                }else{
                    a[i+1].first--;
                }
            }
        } 
    }
    int ans=0;
    for(int i=0;i<siz;i++){
        if(a[i].second==0){
            if(i==0||i==siz-1){
                ans=max(ans,a[i].first);
            }else{
                ans=max(ans,(a[i].first+1)/2);
            }
        }
    }
    cout<<ans+1<<'\n';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    cout<<fixed<<setprecision(9);
    int T=1;
    cin>>T;
    while(T--) abt();
    return 0;
}




詳細信息

Test #1:

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

input:

5
3
010
4
0100
7
0001000
5
11111
6
010101

output:

2
2
4
0
1

result:

ok 5 lines

Test #2:

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

input:

2036
1
1
2
01
2
10
2
11
3
001
3
010
3
011
3
100
3
101
3
110
3
111
4
0001
4
0010
4
0011
4
0100
4
0101
4
0110
4
0111
4
1000
4
1001
4
1010
4
1011
4
1100
4
1101
4
1110
4
1111
5
00001
5
00010
5
00011
5
00100
5
00101
5
00110
5
00111
5
01000
5
01001
5
01010
5
01011
5
01100
5
01101
5
01110
5
01111
5
10000
5...

output:

0
1
1
0
2
2
1
2
1
1
0
3
2
2
2
1
1
1
3
1
1
1
2
1
1
0
4
3
3
3
2
2
2
3
2
2
2
2
1
1
1
4
2
2
1
2
1
1
1
3
1
2
1
2
1
1
0
5
4
4
3
3
3
3
3
2
2
3
2
2
2
2
4
2
2
2
2
1
2
2
3
1
2
1
2
1
1
1
5
2
2
2
2
1
1
1
3
1
1
1
2
1
1
1
4
2
2
1
3
1
1
1
3
1
2
1
2
1
1
0
6
5
5
4
4
4
4
4
3
3
4
3
3
3
3
4
3
2
2
2
2
3
3
3
2
2
2
2
2
2
...

result:

wrong answer 37th lines differ - expected: '1', found: '2'