QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#746768#9565. Birthday GiftacansaidongWA 0ms3752kbC++202.1kb2024-11-14 15:29:222024-11-14 15:29:23

Judging History

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

  • [2024-11-14 15:29:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3752kb
  • [2024-11-14 15:29:22]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
 
const int N=2e5+10;
const int M=0x3f3f3f3f3f3f3f3f;
int a[N];


signed main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while(T--)
	{
		string s,ss,sss;cin>>s;int ans=0;sss=s;
        int n=s.length();
        for(int i=n/2;i<n;i++)
        {
            if(s[i]!='4'&&s[i-1]=='2'||s[i]=='2'||s[i-1]==s[i]) 
            {
                int x=i-1,y=i;
                while(x>=0&&y<n)
                {
                    if(s[x]==s[y]&&s[x]!='4') s[x]='4',s[y]='4';
                    else if(s[x]=='2'||s[y]=='2') s[x]='4',s[y]='4';
                    else break;
                    x--;y++;
                    while(x>0&&s[x]=='4') x--;
                    while(y<n-1&&s[y]=='4') y++;
                }
            }
        }
        for(int i=1;i<n;i++)
        {
            if(s[i]!='4'&&s[i-1]=='2'||s[i]=='2'||s[i-1]==s[i]) 
            {
                int x=i-1,y=i;
                while(x>=0&&y<n)
                {
                    if(s[x]==s[y]&&s[x]!='4') s[x]='4',s[y]='4';
                    else if(s[x]=='2'||s[y]=='2') s[x]='4',s[y]='4';
                    else break;
                    x--;y++;
                    while(x>0&&s[x]=='4') x--;
                    while(y<n-1&&s[y]=='4') y++;
                }
            }
        }
        ans=min(ans,(int)ss.size());
        // cerr<<s;
        s=sss;
        for(int i=1;i<n;i++)
        {
            if(s[i]!='4'&&s[i-1]=='2'||s[i]=='2'||s[i-1]==s[i]) 
            {
                int x=i-1,y=i;
                while(x>=0&&y<n)
                {
                    if(s[x]==s[y]&&s[x]!='4') s[x]='4',s[y]='4';
                    else if(s[x]=='2'||s[y]=='2') s[x]='4',s[y]='4';
                    else break;
                    x--;y++;
                    while(x>0&&s[x]=='4') x--;
                    while(y<n-1&&s[y]=='4') y++;
                }
            }
        }
        for(auto i:s)
        {
            if(i!='4') ss=ss+i;
        }

        cout<<ss.size()<<"\n";
	}
	
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3752kb

input:

5
0110101
01020102
0000021111
1012121010
0100202010

output:

3
4
0
6
3

result:

wrong answer 5th numbers differ - expected: '0', found: '3'