QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140545#6628. Flip it and Stick itzjy00018 3ms6228kbC++172.8kb2023-08-16 08:57:462023-08-16 08:57:47

Judging History

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

  • [2023-08-16 08:57:47]
  • 评测
  • 测评结果:8
  • 用时:3ms
  • 内存:6228kb
  • [2023-08-16 08:57:46]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
int plen,ptop,pstk[40];
char rdc[1<<20],out[1<<20],*rS,*rT;
#define gc() (rS==rT?rT=(rS=rdc)+fread(rdc,1,1<<20,stdin),(rS==rT?EOF:*rS++):*rS++)
#define pc(x) out[plen++]=(x)
#define flush() fwrite(out,1,plen,stdout),plen=0
template<class T=int>inline T read(){
    T x=0;char ch;bool f=1;
    while(!isdigit(ch=gc()))if(ch=='-')f^=1;
    do x=(x<<1)+(x<<3)+(ch^48);while(isdigit(ch=gc()));
    return (f)?(x):(-x);
}
inline int read(char*const s){
	char *t=s,ch;
    while(!isgraph(ch=gc()));
	do (*(t++))=ch;while(isgraph(ch=gc()));
	return (*t)='\000',t-s;
}
template<class T=int>inline void write(T x){
	if(plen>=1000000)flush();
	if(!x)return pc('0'),void();
	if(x<0)pc('-'),x=-x;
	for(;x;x/=10)pstk[++ptop]=x%10;
	while(ptop)pc(pstk[ptop--]+'0');
}
inline void write(const char*s){
	if(plen>=1000000)flush();
	for(int i=0;(*(s+i))!='\000';pc(*(s+(i++))));
}
inline void write(char*const s){
	if(plen>=1000000)flush();
	for(int i=0;(*(s+i))!='\000';pc(*(s+(i++))));
}
typedef pair<LL,LL> PII;
const int N=2e5+5;
int n,m,q;
char s[N],t[10];
struct node{char x;int l,r;}T[N];
inline int A(char a){
	for(int i=1;i<=n;++i)if(s[i]==a)return -1;
	return 0;
}
inline int AA(char a){
	int cnt=0;
	for(int i=1;i<=n;++i)if(s[i]==a)++cnt;
	if((n-cnt)<n/2)return -1;
	int ans=0;
	for(int i=1;i<=q;++i)
		if(T[i].x==a)ans+=T[i].r-T[i].l;
	return ans;
}
inline int AB(char a,char b){
	int ans=0;
	for(int i=2;i<=q;++i)
		if(T[i].x==b)++ans;
	return ans;
}
inline int AAA(char a){
	int cnt=0;
	for(int i=1;i<=n;++i)if(s[i]==a)++cnt;
	if((n-cnt)<n/3)return -1;
	int ans=0;
	priority_queue<int>Q1,Q2;
	for(int i=1;i<=q;++i)
		if(T[i].x!=a)for(int j=1;j<=T[i].r-T[i].l;++j)Q1.push(2);
		else if(T[i].l==T[i].r)Q1.push(1);
		else if(T[i].r-T[i].l>1)Q2.push(T[i].r-T[i].l-1);
	if(s[1]!=a)Q1.push(2);
	if(s[n]!=a)Q1.push(2);
	for(;!Q1.empty()&&!Q2.empty();){
		int x=Q1.top(),y=Q2.top(),z=min(x,y);
		Q1.pop(),Q2.pop(),++ans;
		if(x>z)Q1.push(x-z);
		if(y>z)Q2.push(y-z);
	}
	return ans;
}
inline int ABA(char a,char b){
	int ans=1;
	for(int i=2;i<q;++i)
		if(T[i].x==b&&T[i].l==T[i].r)++ans;
	return ans/2;
}
inline int AXB(char a,char x,char b){
	int ans=0;
	for(int i=3;i<=n;++i)
		ans+=(s[i-2]==a&&s[i-2]==x&&s[i]==b);
	return ans;
}
inline void MAIN(){
	n=read(s+1),m=read(t+1),q=0;
	for(int i=2,j=1;i<=n+1;++i)if(s[i]!=s[j])T[++q]=(node){s[j],j,i-1},j=i;
	if(m==1)write(A(t[1])),pc('\n');
	else if(m==2)write(t[1]==t[2]?AA(t[1]):AB(t[1],t[2])),pc('\n');
	else if(t[1]==t[2]&&t[1]==t[3])write(AAA(t[1])),pc('\n');
	else write(t[1]==t[3]?ABA(t[1],t[2]):AXB(t[1],t[2],t[3])),pc('\n');
}
signed main(){
	for(int T=1;T--;MAIN());
	return flush(),0;
}
/*

*/

詳細信息

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 1ms
memory: 3580kb

input:

1
0

output:

0

result:

ok 1 number(s): "0"

Test #2:

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

input:

1
1

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3848kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 3ms
memory: 5028kb

input:

101001000011101010101001001010010110111111001100110001111101111110110110101011111010001101111001101101010111101100000110001110001100000101111100000110111110001010101101101110001000011010000101000110110010110110100001110001111001010000000010000000101000000100110011101110100111111101111111111110010101...

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

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

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 2ms
memory: 3780kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

-1

result:

ok 1 number(s): "-1"

Subtask #2:

score: 3
Accepted

Test #8:

score: 3
Accepted
time: 1ms
memory: 3412kb

input:

0
01

output:

0

result:

ok 1 number(s): "0"

Test #9:

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

input:

0
10

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

01
01

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

01
10

output:

0

result:

ok 1 number(s): "0"

Test #12:

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

input:

1010101010
10

output:

5

result:

ok 1 number(s): "5"

Test #13:

score: 0
Accepted
time: 2ms
memory: 3848kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #14:

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

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 3ms
memory: 6228kb

input:

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...

output:

100000

result:

ok 1 number(s): "100000"

Test #16:

score: 0
Accepted
time: 3ms
memory: 4816kb

input:

000110111001011000010001010010010000010100100000011101010000001000110011100000011011100101110110000001000000000011001010001101001110011111001101110010001100000000010000000100100011000111010011100110011101100011000100011001010000010001001010010101100000100000010010110000000001011100100001000010100100...

output:

43860

result:

ok 1 number(s): "43860"

Test #17:

score: 0
Accepted
time: 3ms
memory: 4876kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

44072

result:

ok 1 number(s): "44072"

Subtask #3:

score: 4
Accepted

Dependency #2:

100%
Accepted

Test #18:

score: 4
Accepted
time: 1ms
memory: 3576kb

input:

0
01

output:

0

result:

ok 1 number(s): "0"

Test #19:

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

input:

0
10

output:

0

result:

ok 1 number(s): "0"

Test #20:

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

input:

01
01

output:

1

result:

ok 1 number(s): "1"

Test #21:

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

input:

01
10

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

input:

1
00

output:

0

result:

ok 1 number(s): "0"

Test #23:

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

input:

1
11

output:

0

result:

ok 1 number(s): "0"

Test #24:

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

input:

10
00

output:

0

result:

ok 1 number(s): "0"

Test #25:

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

input:

11
11

output:

-1

result:

ok 1 number(s): "-1"

Test #26:

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

input:

1010101010
10

output:

5

result:

ok 1 number(s): "5"

Test #27:

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

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #28:

score: 0
Accepted
time: 2ms
memory: 3844kb

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #29:

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

input:

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...

output:

100000

result:

ok 1 number(s): "100000"

Test #30:

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

input:

001000001110000110101100000001110000011000100001010001110010010101110110111000000000100000010110100000101110001000001010000000010101000010001000100010111010000110000001000001100110001010000010000101001001110100000011001000100100100101000101000100000100001001000000111000100101010010101100101001001010...

output:

43612

result:

ok 1 number(s): "43612"

Test #31:

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

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

43815

result:

ok 1 number(s): "43815"

Test #32:

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

input:

0011001101
00

output:

2

result:

ok 1 number(s): "2"

Test #33:

score: 0
Accepted
time: 2ms
memory: 3856kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1

result:

ok 1 number(s): "1"

Test #34:

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

input:

011110101001110000100100101010111010100110011010001001000110011111010101111000110100000110010011001010111001000110000110001110110100011111100010111010101101001100101110100001101111110110000100110110111001000001101110011010100110000111101101101111011000110010100100100001000011010100000100110101001000...

output:

50001

result:

ok 1 number(s): "50001"

Test #35:

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

input:

111011011000111010010001101100000110011000000101110011111110010110001010001000011100011100101011110101101001011101010011110100011101111111000011110101010001000011000100110001011110100010111101111110011001010110011001110111001011000000110100000011001110110110000101010100001001110100111010100100100101...

output:

-1

result:

ok 1 number(s): "-1"

Test #36:

score: 0
Accepted
time: 2ms
memory: 5056kb

input:

110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110110...

output:

50000

result:

ok 1 number(s): "50000"

Test #37:

score: 0
Accepted
time: 2ms
memory: 3924kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

99999

result:

ok 1 number(s): "99999"

Test #38:

score: 0
Accepted
time: 3ms
memory: 4864kb

input:

000100100001010000001000011101100101000000000000100000101000100110111001000100000000001000100011101100010010100100000011110101010010010001000001000010000011101000011101010010000110000001000000010100001100010011001001010100010001010000001101101001010110011001000001110000001100010001000101000010110000...

output:

24091

result:

ok 1 number(s): "24091"

Test #39:

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

input:

011000011010000110001000000000100110011001001101011100010010100000100011010110010010011101100000011100110100001010000000100010011100001010010100000100000000100010010101110000001000001010111001100001001011101011110011100101110110101010110000100010001110111010111010000000101111010001010000001111111001...

output:

58668

result:

ok 1 number(s): "58668"

Subtask #4:

score: 0
Wrong Answer

Test #40:

score: 5
Accepted
time: 1ms
memory: 3464kb

input:

11
011

output:

0

result:

ok 1 number(s): "0"

Test #41:

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

input:

0
110

output:

0

result:

ok 1 number(s): "0"

Test #42:

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

input:

01
100

output:

0

result:

ok 1 number(s): "0"

Test #43:

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

input:

110
110

output:

1

result:

ok 1 number(s): "1"

Test #44:

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

input:

010
001

output:

0

result:

ok 1 number(s): "0"

Test #45:

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

input:

001001001001
001

output:

4

result:

ok 1 number(s): "4"

Test #46:

score: 0
Accepted
time: 2ms
memory: 3892kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok 1 number(s): "0"

Test #47:

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

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

0

result:

ok 1 number(s): "0"

Test #48:

score: -5
Wrong Answer
time: 3ms
memory: 4976kb

input:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

0

result:

wrong answer 1st numbers differ - expected: '24856', found: '0'

Subtask #5:

score: 0
Wrong Answer

Test #53:

score: 5
Accepted
time: 1ms
memory: 3460kb

input:

11
011

output:

0

result:

ok 1 number(s): "0"

Test #54:

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

input:

01
100

output:

0

result:

ok 1 number(s): "0"

Test #55:

score: -5
Wrong Answer
time: 1ms
memory: 3412kb

input:

011
011

output:

0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'

Subtask #6:

score: 0
Skipped

Dependency #4:

0%