Toyota Programming Contest 2024#4(AtCoder Beginner Contest 348)F. Oddly Similar(bitset暴力)

该篇文章介绍了一种使用bitset数据结构解决AtCoder编程竞赛中的问题,通过维护每行的奇偶性并异或同一列相同值的bitset,快速统计具有奇数相同值的行对数量,时间复杂度为O(n*m*n/64)。

题目

n(n<=2e3)行m(m<=2e3)列,第i行第j列的数a[i][j](1<=a[i][j]<=999)

称x行和y行这两行是相似的,当且仅当满足x[i]=y[i]的列有奇数个

统计i行和j行(i<=j)相似的对数(i,j),输出这个值

思路来源

Submission #52127725 - Toyota Programming Contest 2024#4(AtCoder Beginner Contest 348)

题解

注意到每次给在同一列里的相同的值一起操作,

相当于给这些行之前维护的奇偶性取反

给每一行维护一个bitset表示当前答案的奇偶性,

每次考虑每一列,给这一列每一个相同颜色维护一个bitset,

每次令每一行的当前答案,异或当前颜色的bitset即可

复杂度O(n*m*n/64)

代码

// Problem: F - Oddly Similar
// Contest: AtCoder - Toyota Programming Contest 2024#4(AtCoder Beginner Contest 348)
// URL: https://atcoder.jp/contests/abc348/tasks/abc348_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef double db;
typedef pair<ll,int> P;
#define fi first
#define se second
#define pb push_back
#define dbg(x) cerr<<(#x)<<":"<<x<<" ";
#define dbg2(x) cerr<<(#x)<<":"<<x<<endl;
#define SZ(a) (int)(a.size())
#define sci(a) scanf("%d",&(a))
#define scll(a) scanf("%lld",&(a))
#define pt(a) printf("%d",a);
#define pte(a) printf("%d\n",a)
#define ptlle(a) printf("%lld\n",a)
#define debug(...) fprintf(stderr, __VA_ARGS__)
const int N=2e3+5,M=1e3+5;
int n,m,a[N][N],sum;
bitset<N>ans[N];
void sol(){
	sci(n),sci(m);
	rep(i,1,n){
		rep(j,1,m){
			sci(a[i][j]);
		}
	}
	rep(j,1,m){
		bitset<N>b[M];
		rep(i,1,n){
			ans[i]^=b[a[i][j]];
			b[a[i][j]][i]=1;
		}
	}
	rep(i,1,n){
		sum+=ans[i].count();
	}
	printf("%d\n",sum);
}
int main(){
	sol();
	return 0;
}

### AtCoder Beginner Contest 388 Problems and Solutions #### Problem A: Sample Problem Title In this problem, contestants are asked to solve a basic algorithmic challenge that tests fundamental coding skills. The task involves processing input data according to specific rules outlined in the contest guidelines. For instance, consider an example where participants need to determine whether a given string meets certain criteria: ```python def check_string(s): if s.startswith(&#39;A&#39;) and s.endswith(&#39;Z&#39;): return "Yes" else: return "No" print(check_string("ABC")) # Output should be based on provided conditions. ``` The solution approach focuses on understanding the requirements clearly before implementing any logic[^1]. #### Problem B: Another Example Task This section would detail another type of question from ABC 388 which might involve more complex algorithms or data structures compared to Problem A. It could cover topics like sorting arrays, searching within lists, etc., depending upon what was actually featured during the event. An illustrative code snippet demonstrating how one may tackle such issues can look as follows: ```cpp #include <bits/stdc++.h> using namespace std; int main() { vector<int> numbers = { /* Input values */ }; sort(numbers.begin(), numbers.end()); // Further operations with sorted list... } ``` Contestants must carefully read through all instructions while attempting these types of questions. #### General Tips for Participating in Contests Like This One Preparing adequately prior to participating includes practicing similar past papers extensively along with reviewing relevant materials related to common themes encountered frequently across various contests hosted by platforms like AtCoder. Additionally, staying updated about recent changes made either concerning submission formats or evaluation methods ensures smoother participation without unexpected surprises arising midway into solving tasks at hand[^3].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小衣同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值