CSES - Leirikisa 1 - Results
Submission details
Task:ratar
Sender:zxc
Submission time:2016-07-27 14:47:34 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

In file included from /usr/include/c++/4.8/bits/hashtable.h:35:0,
                 from /usr/include/c++/4.8/unordered_map:47,
                 from /usr/include/x86_64-linux-gnu/c++/4.8/bits/stdc++.h:115,
                 from input/code.cpp:1:
/usr/include/c++/4.8/bits/hashtable_policy.h: In instantiation of 'struct std::__detail::_Hash_code_base<std::pair<int, std::pair<int, int> >, std::pair<const std::pair<int, std::pair<int, int> >, int>, std::__detail::_Select1st, std::hash<std::pair<int, std::pair<int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>':
/usr/include/c++/4.8/bits/hashtable_policy.h:1402:10:   required from 'struct std::__detail::_Hashtable_base<std::pair<int, std::pair<int, int> >, std::pair<const std::pair<int, std::pair<int, int> >, int>, std::__detail::_Select1st, std::equal_to<std::pair<int, std::pair<int, int> > >, std::hash<std::pair<int, std::pair<int, int> > >, std::__detail::_Mod_range_hashing, std::__detail::_Defau...

Code

#include <bits/stdc++.h>
using namespace std;
int t[55][55];
int getSum(int x1, int y1, int x2, int y2) {
    return t[x2+1][y2+1] - t[x2+1][y1] - t[x1][y2+1] + t[x1][y1];
}
unordered_map<pair<int, pair<int, int> >, int > st1;
unordered_map<pair<int, pair<int, int> >, int> st2;
unordered_map<pair<int, pair<int, int> >, int> st3;
unordered_map<pair<int, pair<int, int> >, int> st4;
int main() {
    int n;
    cin>>n;
    for(int i = 0; i < n ;++i) {
	for(int j = 0; j < n; ++j) {
	    cin>>t[i+1][j+1];
	    t[i+1][j+1] += t[i][j+1] + t[i+1][j] - t[i][j];
	    //cout<<t[i+1][j+1]<<' ';
	}
	//cout<<'\n';
    }
    for(int i = 0; i < n; ++i) {
	for(int j = 0; j < n ;++j) {
	    for(int k = i; k < n; ++k) {
		for(int l = j; l < n; ++l) {
		    int sum = getSum(i, j, k, l);
		    st1[{sum, {i, j}}]++;
		    st2[{sum, {k+1, j}}]++;
		    st3[{sum, {k+1, l+1}}]++;
		    st4[{sum, {i, l+1}}]++;
		}
	    }
	}
    }
    long long ans = 0;
    for(int i = 0; i < n; ++i) {
	for(int j = 0; j < n ;++j) {
	 //   cout<<getSum(i, j,i , j)<<' ';// st1[{getSum(i, j, i, j), {i, j}}]<<' ';
	    for(int k = i; k < n; ++k) {
		for(int l = j; l < n; ++l) {
		    int sum = getSum(i, j, k, l);

		    ans += st1[{sum, {k+1, l+1}}];
		    ans += st2[{sum, {i, l+1}}];
		    ans += st3[{sum, {i, j}}];
		    ans += st4[{sum, {k+1, j}}];
		}
	    }
	}
//	cout<<'\n';
    }
    cout<<ans/2<<'\n';
}