QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#141307#6628. Flip it and Stick itchenxinyang20060 1ms3404kbC++143.0kb2023-08-17 10:36:252023-08-17 10:36:27

Judging History

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

  • [2023-08-17 10:36:27]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3404kb
  • [2023-08-17 10:36:25]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
	if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
	if(x > y) x = y;
}

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}


/*ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;	
	}
	return ans;
}*/
int TEST,n,type;
char s[200005],t[5];

int solve1(char ch){
	rep(i,1,n) if(s[i] == ch) return -1;
	return 0;
}

void rev(){
	rep(i,1,n){
		if(s[i] == '0') s[i] = '1';
		else s[i] = '0';
	}
	rep(i,1,type){
		if(t[i] == '0') t[i] = '1';
		else t[i] = '0';
	}
}

int solve2dif(){
	int cnt = 1;
	rep(i,2,n) if(s[i] != s[i - 1]) cnt++;
	if(s[1] == '0') return (cnt - 1) / 2;
	return cnt / 2;
}

int solve2sam(){
	int cnt = 0,ans = 0;
	rep(i,1,n){
		if(s[i] == '0') cnt--;
		else cnt++;
	}
	if(cnt < -1) return -1;
	rep(i,2,n) if(s[i] == '0' && s[i - 1] == '0') ans++;
	return ans;
}

int solve3010(){
	int ans = 0;
	rep(i,2,n - 1) if(s[i - 1] == '0' && s[i] == '1' && s[i + 1] == '0') ans++;
	return (ans + 1) / 2;
}

int solve3001(){
	int ans = 0;
	for(int l = 1,r;l <= n;l = r + 1){
		r = l;
		if(s[l] == '1') continue;
		while(r < n && s[r + 1] == s[r]) r++;
		if(l != r && r != n) ans++;
	}
	return ans;
}

int m;
int b[200005];
int solve3pure(){
	int cur = 0,sum = 0,p1 = 0,p2 = 0;
	rep(i,1,n){
		if(s[i] == '0'){
			cur++;
		}else{
			b[++m] = cur;
			cur = 0;
		} 
	}
	b[++m] = cur;
	rep(i,1,m) sum += b[i];
	if(sum > 2 * m) return -1;

	sum = 0;
	rep(i,1,m){
		if(b[i] > 2) p1 += (b[i] - 2) / 2;
		else if(!b[i]) p2++;
		sum += max(b[i] - 2,0);
	}
	return sum - min(p1,p2);
}

void solve(){
	scanf("%s",s + 1);
	n = strlen(s + 1);
	scanf("%s",t + 1);
	type = strlen(t + 1);
	if(type == 1){
		printf("%d\n",solve1(t[1]));
		return;
	}else if(type == 2){
		if(t[1] != t[2]){
			if(t[1] == '0') rev();
			printf("%d\n",solve2dif());
			return;
		}else{
			if(t[1] == '1') rev();
			printf("%d\n",solve2sam());
			return;
		}
	}
	if(t[1] == '1') rev();

	if(t[2] == '0' && t[3] == '1'){
		printf("%d\n",solve3001());
	}else if(t[2] == '0' && t[3] == '0'){
		printf("%d\n",solve3pure());
	}else if(t[2] == '1' && t[3] == '0'){
		printf("%d\n",solve3010());
	}else{
		rev();
		reverse(s + 1,s + n + 1);reverse(t + 1,t + type + 1);
		printf("%d\n",solve3001());
	}	
}

int main(){
//	freopen("shin2.in","r",stdin);
//	TEST = 1;
//	scanf("%d",&TEST);
	while(TEST--) 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: 0ms
memory: 3392kb

input:

1
0

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 0
Wrong Answer
time: 1ms
memory: 3256kb

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: 1ms
memory: 3404kb

input:

11
011

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #5:

score: 0
Wrong Answer

Test #53:

score: 0
Wrong Answer
time: 1ms
memory: 3292kb

input:

11
011

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #6:

score: 0
Skipped

Dependency #4:

0%