其他分享
首页 > 其他分享> > AtCoder Beginner Contest 258 G - Triangle

AtCoder Beginner Contest 258 G - Triangle

作者:互联网

O(M*sqrt(M))的做法超时
考虑直接暴力,用bitset实现小常数,时间复杂度O(N^3 / 64)
#include<bits/stdc++.h>
using namespace std;

#define fr first
#define se second
#define et0 exit(0);
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef unsigned long long ULL;

const int INF = 0X3f3f3f3f, N = 3000 + 10, MOD = 1e9 + 7;
const double eps = 1e-7;

int g[N][N];

bitset<N> bt[N];

void work() {
	int n;
	cin>>n;
	rep(i,1,n) 
		rep(j,1,n){
			char c;
			cin>>c;
			if(c=='1') g[i][j]=1,bt[i][j]=1;
		}
	
	LL res=0;
	rep(i,1,n)
		rep(j,i+1,n)
			if(g[i][j]) res+=(bt[i]&bt[j]).count();
		
	cout<<res/3;
}

signed main() {
	
	work();

	return 0;
}

标签:AtCoder,typedef,Triangle,int,rep,long,bt,258,define
来源: https://www.cnblogs.com/xhy666/p/16439695.html