比赛 20241023 评测结果 AAAAAAAAAAAATTTATTTT
题目名称 Cowreography 最终得分 65
用户昵称 ┭┮﹏┭┮ 运行时间 14.771 s
代码语言 C++ 内存使用 7.02 MiB
提交时间 2024-10-23 11:27:43
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e6+10;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}


int n,k,m;
char c;
int a[N],b[N];
ll ans = 0;
set<pii>s[2];
int main(){
	freopen("cowreography.in","r",stdin);
	freopen("cowreography.out","w",stdout);
	n = read(),k = read();
	for(int i = 1;i <= n;i++){
		cin>>c;
		if(c == '1')a[i] = 1;
	}
	for(int i = 1;i <= n;i++){
		cin>>c;
		if(c == '1')b[i] = 1;
	}
	for(int i = 1;i <= n;i++){
		if(a[i] == b[i])continue;
		if(s[b[i]].size()){
			auto x = lower_bound(s[b[i]].begin(),s[b[i]].end(),make_pair(i % k,0));
			if(x == s[b[i]].end())x = s[b[i]].begin();
			auto w = *x;
			ans += (i - w.se + k - 1) / k;
			s[b[i]].erase(x);
		}
		else s[a[i]].insert({i % k,i});
	}
	printf("%lld\n",ans);
	

	return 0;

}