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 11:43:06
2017-05-27 11:29:26
2017-05-27 11:23:08
Task:Grid
Sender:Ace of Spades
Submission time:2017-05-27 11:43:06
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:30:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int64_t k = 0; k < rows[i].size(); ++k) {
                                           ^

Code

#include<iostream>
#include<vector>

using namespace std;

int main(void) {
    int64_t n, m;
    cin >> n >> m;

    vector<vector<uint64_t>> rows(n, vector<uint64_t>((m+63)/64));

    for (int64_t i = 0; i < n; ++i) {
	string r;
	cin >> r;
	for (int64_t j = 0; j < (m+63)/64; ++j) {
	    int64_t res = 0;
	    for (int64_t k = 0; k < 64; ++k) {
		if (j*64 + k < m) {
		    res += ((uint64_t)1<<(uint64_t)k) * (r[j*64+k] - '0');
		}
	    }
	    rows[i][j] = res;
	}
    }

    int64_t res = 0;
    for (int64_t i = 0; i < n; ++i) {
	for (int64_t j = i+1; j < n; ++j) {
	    int64_t cnt = 0;
	    for (int64_t k = 0; k < rows[i].size(); ++k) {
		cnt += __builtin_popcountll(rows[i][k] & rows[j][k]);
	    }
	    res += cnt*(cnt-1)/2;
	}
    }
    cout << res << '\n';
    return 0;
}