| Task: | ratar |
| Sender: | Hansuzu |
| Submission time: | 2016-07-27 15:25:42 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.09 s | details |
| #2 | ACCEPTED | 0.09 s | details |
| #3 | ACCEPTED | 0.08 s | details |
| #4 | ACCEPTED | 0.08 s | details |
| #5 | ACCEPTED | 0.08 s | details |
| #6 | ACCEPTED | 0.07 s | details |
| #7 | WRONG ANSWER | 0.09 s | details |
| #8 | ACCEPTED | 0.17 s | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | TIME LIMIT EXCEEDED | -- | details |
| #12 | TIME LIMIT EXCEEDED | -- | details |
| #13 | TIME LIMIT EXCEEDED | -- | details |
Code
#include <iostream>
#include <map>
#define F first
#define S second
using namespace std;
int N;
int tbl[55][55];
int sm[55][55];
int csm(int x1, int y1, int x2, int y2){
return sm[x2][y2]-sm[x1-1][y2]-sm[x2][y1-1]+sm[x1-1][y1-1];
}
map<int, int> sms1[55][55];
map<int, int>::iterator it1;
map<int, int>::iterator it1e;
map<int, int> sms2[55][55];
map<int, int>::iterator it2;
map<int, int>::iterator it2e;
void clrsms(){
for (int i=0; i<55; ++i)
for (int j=0; j<55; ++j)
for (int s=0; s<2552; ++s)
sms1[i][j].clear(), sms2[i][j].clear();
}
long long ans;
void calc(){
while (it1!=it1e && it2!=it2e){
if (it1->F<it2->F) ++it1;
else if (it1->F>it2->F) ++it2;
else{
ans+=it1->S*it2->S;
++it1; ++it2;
}
}
}
int main(){
cin >>N;
for (int i=1; i<=N; ++i){
for (int j=1; j<=N; ++j){
cin >> tbl[i][j];
}
}
for (int i=1; i<=N; ++i){
for (int j=1; j<=N; ++j){
sm[i][j]=tbl[i][j]+sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1];
}
}/*
while (1){
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << csm(x1, y1, x2, y2) << endl;
}*/
for (int x1=1; x1<=N; ++x1){
for (int y1=1; y1<=N; ++y1){
for (int x2=x1; x2<=N; ++x2){
for (int y2=y1; y2<=N; ++y2){
int smi=csm(x1, y1, x2, y2);
++sms1[x1][y1][smi];
++sms2[x2][y2][smi];
}
}
}
}
for (int x=1; x<N; ++x){
for (int y=1; y<N; ++y){
it1=sms2[x][y].begin();
it1e=sms2[x][y].end();
it2=sms1[x+1][y+1].begin();
it2e=sms1[x+1][y+1].end();
calc();
}
}
clrsms();
for (int x1=1; x1<=N; ++x1){
for (int y1=1; y1<=N; ++y1){
for (int x2=x1; x2<=N; ++x2){
for (int y2=y1; y2<=N; ++y2){
int smi=csm(x1, y1, x2, y2);
if (smi<0) smi+=5200;
++sms1[x1][y2][smi];
++sms2[x2][y1][smi];
}
}
}
}
for (int x=1; x<N; ++x){
for (int y=2; y<=N; ++y){
it1=sms2[x][y].begin();
it1e=sms2[x][y].end();
it2=sms1[x+1][y-1].begin();
it2e=sms1[x+1][y-1].end();
calc();
}
}
cout << ans << "\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: WRONG ANSWER
| input |
|---|
| 10
420 425 490 727 888 391 514 82... |
| correct output |
|---|
| 5 |
| user output |
|---|
| 9 |
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: TIME LIMIT EXCEEDED
| input |
|---|
| 41
475 533 -726 -189 401 -389 667... |
| correct output |
|---|
| 17456 |
| user output |
|---|
| (empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 49
495 -512 159 -874 751 -817 567... |
| correct output |
|---|
| 48443 |
| user output |
|---|
| (empty) |
Test 11
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 49
521 -51 -778 -977 955 -172 695... |
| correct output |
|---|
| 39082 |
| user output |
|---|
| (empty) |
Test 12
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 50
500 500 500 500 500 500 500 50... |
| correct output |
|---|
| 4236645 |
| user output |
|---|
| (empty) |
Test 13
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 50
933 -493 -881 936 -889 -922 -5... |
| correct output |
|---|
| 37917 |
| user output |
|---|
| (empty) |
