QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140777 | #6628. Flip it and Stick it | xyk2333 | 0 | 1ms | 3696kb | C++14 | 1.8kb | 2023-08-16 20:08:02 | 2023-08-16 20:09:24 |
answer
//HEZ NOIP模拟 8.16 T2
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N],n,m;
string s,t;
int sub1()
{
for(int i=0;i<n;i++)if(s[i]==t[0])return -1;
return 0;
}
int sub2()
{
int res=0;
while(n&&s[n-1]==t[0])n--;
for(int i=0;i<n;i++)res+=(s[i]==t[0]&&s[i+1]!=t[0]);
return res;
}
int sub3()
{
int cnt=0,res=0;
for(int i=0;i<n;i++)cnt+=(s[i]==t[0]);
if(cnt>(n+1)/2)return -1;
for(int i=1;i<n;i++)res+=(s[i]==t[0]&&s[i]==s[i-1]);
return res;
}
int sub4()
{
if(t[0]!=t[1])
{
reverse(s.begin(),s.end());
reverse(t.begin(),t.end());
}
int res=0;
while(n&&s[n-1]==t[0])n--;
for(int i=1;i<n-1;i++)res+=(s[i]==t[0]&&s[i-1]==s[i]&&s[i+1]!=t[0]);
return res;
}
int sub5()
{
int ans=0;
for(int i=1;i<n-1;i++)ans+=(s[i]==t[1]&&s[i-1]!=s[i]&&s[i+1]!=s[i]);
return (ans+1)/2;
}
int sub6()
{
int A=0,B=0,res=0;
for(int i=0,p=-1;i<=n;i++)
{
if(i<n&&s[i]==t[0])continue;
int len=i-p-1;
if(len<2)a[++A]=2-len;
if(len>2)b[++B]=len-2;
p=i;
}
sort(a+1,a+A+1,greater<int>());
sort(b+1,b+B+1,greater<int>());
for(int i=1,l=1,r=A;i<=B;i++)
{
while(l<=r&&b[i]>=2)b[i]-=a[l++],res++;
if(b[i])
{
if(l>r)return -1;
if(--a[r]==0)r--;
res++;
}
}
return res;
}
int solve()
{
cin>>s>>t;
n=s.size(),m=t.size();
for(int i=0;i<n;i++)s[i]-='0';
for(int i=0;i<m;i++)t[i]-='0';
if(m==1)return sub1();
if(m==2&&t[0]!=t[1])return sub2();
if(m==2)return sub3();
if(m==3&&t[0]!=t[2])return sub4();
if(m==3&&t[0]!=t[1])return sub5();
if(m==3)return sub6();
return -2;
}
int main()
{
// freopen("shin.in","r",stdin);
// freopen("shin.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
int T;
cin>>T;
while(T--)printf("%d\n",solve());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3668kb
input:
1 0
output:
-2
result:
wrong answer 1st numbers differ - expected: '0', found: '-2'
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 1ms
memory: 3540kb
input:
0 01
output:
result:
wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #40:
score: 0
Wrong Answer
time: 0ms
memory: 3692kb
input:
11 011
output:
-2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
result:
wrong answer 1st numbers differ - expected: '0', found: '-2'
Subtask #5:
score: 0
Wrong Answer
Test #53:
score: 0
Wrong Answer
time: 1ms
memory: 3696kb
input:
11 011
output:
-2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
result:
wrong answer 1st numbers differ - expected: '0', found: '-2'
Subtask #6:
score: 0
Skipped
Dependency #4:
0%