CSES - Leirikisa 1 - Results
Submission details
Task:ratar
Sender:zxc
Submission time:2016-07-27 15:04:16 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.06 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.06 sdetails
#6ACCEPTED0.06 sdetails
#7ACCEPTED0.05 sdetails
#8ACCEPTED0.09 sdetails
#9ACCEPTED0.18 sdetails
#10ACCEPTED0.30 sdetails
#11ACCEPTED0.32 sdetails
#12ACCEPTED0.34 sdetails
#13ACCEPTED0.32 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:52:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int ii = 0; ii < v2.size(); ++ii) {
                               ^
input/code.cpp:62:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int ii = 0; ii < v2.size(); ++ii) {
                               ^

Code

#include <bits/stdc++.h>
#define F first
#define S second
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];
}
int st1[55][55];
int st2[55][55];
int st3[55][55];
int st4[55][55];
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';
    }
    vector<pair<int, pair<pair<int, int>, pair<int, int> > > > v;
    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);
		    v.push_back({sum, {{i, j}, {k, l}}});
		}
	    }
	}
    }
    sort(v.begin(), v.end());
    long long ans = 0;
    while(v.size()) {
	int ed = v.back().F;
    vector<pair<int, pair<pair<int, int>, pair<int, int> > > > v2;
	while(v.size() && v.back().F == ed) {
	    int i = v.back().S.F.F;
	    int j = v.back().S.F.S;
	    int k = v.back().S.S.F;
	    int l = v.back().S.S.S;
	    st1[i][j]++;
	    st2[k+1][j]++;//}}]++;
	    st3[k+1][l+1]++;
	    st4[i][l+1]++;
	    v2.push_back(v.back());
	    v.pop_back();
	}
	for(int ii = 0; ii < v2.size(); ++ii) {
	    int i = v2[ii].S.F.F;
	    int j = v2[ii].S.F.S;
	    int k = v2[ii].S.S.F;
	    int l = v2[ii].S.S.S;
	    ans += st3[i][j];
	    ans += st4[k+1][j];
	    ans += st1[k+1][l+1];
	    ans +=st2[i][l+1];
	}
	for(int ii = 0; ii < v2.size(); ++ii) {
	    int i = v2[ii].S.F.F;
	    int j = v2[ii].S.F.S;
	    int k = v2[ii].S.S.F;
	    int l = v2[ii].S.S.S;
	    st1[i][j]--;
	    st2[k+1][j]--;//}}]++;
	    st3[k+1][l+1]--;
	    st4[i][l+1]--;
	}
    }
    cout<<ans/2<<'\n';
}

Test details

Test 1

Verdict: ACCEPTED

input
3
1 2 3
2 3 4
3 4 8

correct output
7

user output
7

Test 2

Verdict: ACCEPTED

input
4
-1 -1 -1 -1
1 2 3 4
1 2 3 4
1 2 3 4

correct output
10

user output
10

Test 3

Verdict: ACCEPTED

input
5
-1 -1 -1 -1 -1
-2 -2 -2 -2 -2
-3 -3 -3 -3 -3
-4 -4 -4 -4 -4
...

correct output
36

user output
36

Test 4

Verdict: ACCEPTED

input
2
1 -1
-1 1

correct output
2

user output
2

Test 5

Verdict: ACCEPTED

input
5
1 -1 1 -1 1
-1 1 -1 1 -1
1 -1 1 -1 1
-1 1 -1 1 -1
...

correct output
380

user output
380

Test 6

Verdict: ACCEPTED

input
10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 1 0
0 1 1 0 0 0 0 1 1 0
...

correct output
7354

user output
7354

Test 7

Verdict: ACCEPTED

input
10
420 425 490 727 888 391 514 82...

correct output
5

user output
5

Test 8

Verdict: ACCEPTED

input
31
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
667480

user output
667480

Test 9

Verdict: ACCEPTED

input
41
475 533 -726 -189 401 -389 667...

correct output
17456

user output
17456

Test 10

Verdict: ACCEPTED

input
49
495 -512 159 -874 751 -817 567...

correct output
48443

user output
48443

Test 11

Verdict: ACCEPTED

input
49
521 -51 -778 -977 955 -172 695...

correct output
39082

user output
39082

Test 12

Verdict: ACCEPTED

input
50
500 500 500 500 500 500 500 50...

correct output
4236645

user output
4236645

Test 13

Verdict: ACCEPTED

input
50
933 -493 -881 936 -889 -922 -5...

correct output
37917

user output
37917