Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 13:08:31
Task:Grid
Sender:KnowYourArchitecture
Submission time:2017-05-27 13:08:31
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:14:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<l.size();++j)v[i].set(j,l[j]=='1');
                              ^

Code

#include <bits/stdc++.h>

using namespace std;
bitset<3000> v[3000];
typedef long long ll;
int main() {
    cin.tie(nullptr);
    cin.sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;++i){
        string l;
        cin>>l;
        for(int j=0;j<l.size();++j)v[i].set(j,l[j]=='1');
    }
    ll r = 0;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            auto k = v[i]&v[j];
            ll a = k.count()-1;
            r+=(a*a+a)/2;
        }
    }
    cout<<r<<endl;
    return 0;
}