QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#746768 | #9565. Birthday Gift | acansaidong | WA | 0ms | 3752kb | C++20 | 2.1kb | 2024-11-14 15:29:22 | 2024-11-14 15:29:23 |
Judging History
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'