codeforce Gym 100342J Triatrip (bitset)

傻逼题,但是为什么别人的O(n^3)不会T?只是因为用了bitset优化。。。

附上一张bitset基本操作的表

#include<bits/stdc++.h>
using namespace std;

const int maxn = 1500+2;

char g[maxn][maxn];

bitset<maxn> b1[maxn],b2[maxn],res;

#define local
int main()
{
#ifdef local
    freopen("triatrip.in","r",stdin);
    freopen("triatrip.out","w",stdout);
#endif // local
    int n; scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%s",g[i]);
    }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            if(g[i][j] == '+') b1[i][j] = 1, b2[j][i] = 1;

    long long ans = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) if(b1[i][j]){
            res = b1[j]&b2[i];
            ans += res.count();
        }

    printf("%I64d\n",ans/3);
    return 0;
}

 

posted @ 2015-08-06 18:53  陈瑞宇  阅读(306)  评论(0编辑  收藏  举报