Submission #281698

# Submission time Handle Problem Language Result Execution time Memory
281698 2020-08-23T10:03:48 Z peti1234 Rectangles (IOI19_rect) C++17
59 / 100
2727 ms 1048580 KB
#include <bits/stdc++.h>

using namespace std;
const int c=2602;
bool v[c][c], t[c][c];
int n, m, ans, ks, ko, ns, no, mini, db, fel[c][c], le[c][c], bal[c][c], jobb[c][c];
vector<pair<pair<int, int>, pair<int, int> > > ch;
void add(int a, int b, int c, int d) {ch.push_back({{a, b}, {c, d}});}
long long count_rectangles(vector<vector<int>> sz) {
    n=sz.size(), m=sz[0].size();

    vector<int> s;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            while(s.size()>0 && sz[i][j]>=sz[i][s.back()]) jobb[i][1+s.back()]=j-1, s.pop_back();
            s.push_back(j);
        }
        while(s.size()>0) jobb[i][1+s.back()]=-1, s.pop_back();
        for (int j=m-1; j>=0; j--) {
            while(s.size()>0 && sz[i][j]>=sz[i][s.back()]) bal[i][-1+s.back()]=j+1, s.pop_back();
            if (j) s.push_back(j);
        }
        while(s.size()>0) bal[i][-1+s.back()]=-1, s.pop_back();
    }
    for (int j=0; j<m; j++) {
        for (int i=0; i<n; i++) {
            while(s.size()>0 && sz[i][j]>=sz[s.back()][j]) le[1+s.back()][j]=i-1, s.pop_back();
            s.push_back(i);
        }
        while(s.size()>0) le[1+s.back()][j]=-1, s.pop_back();
        for (int i=n-1; i>=0; i--) {
            while(s.size()>0 && sz[i][j]>=sz[s.back()][j]) fel[-1+s.back()][j]=i+1, s.pop_back();
            if (i) s.push_back(i);
        }
        while(s.size()>0) fel[-1+s.back()][j]=-1, s.pop_back();
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            int ba=bal[i][j], jo=jobb[i][j], fe=fel[i][j], l=le[i][j];
            add(i, j, l, jo), add(i, ba, l, j), add(fe, j, i, jo), add(fe, ba, i, j);
            if (jo!=-1) add(i, j, le[i][jo], jo);
            if (l!=-1) add(i, j, l, jobb[l][j]);
        }
    }
    sort(ch.begin(), ch.end());
    for (int i=0; i<ch.size(); i++) if (ch[i]!=ch[i-1]) {
        ks=ch[i].first.first, ko=ch[i].first.second, ns=ch[i].second.first, no=ch[i].second.second, mini=min({ks, ko, ns, no});
        if (mini!=-1 && ks && ko && ns<n-1 && no<m-1 && ks<=ns && ko<=no) {
            int r=0;
            for (int j=ko; j<=no; j++) {
                if (le[ks][j]!=-1 && le[ks][j]<ns) r++;
                if (fel[ns][j]>ks) r++;
            }
            for (int i=ks; i<=ns; i++) {
                if (jobb[i][ko]!=-1 && jobb[i][ko]<no) r++;
                if (bal[i][no]>ko) r++;
            }
            if (!r) ans++;
        }
    }
    return ans;

}




/*
int b1, b2;
vector<vector<int>> b3;
int main()
{
    cin >> b1 >> b2;
    b3.resize(b1);
    for (int i=0; i<b1; i++) for (int j=0; j<b2; j++) {
        int x; cin >> x;
        b3[i].push_back(x);
    }
    cout << count_rectangles(b3);
    return 0;
}
*/
/*
6 5
4 8 7 5 6
7 4 10 3 5
9 7 20 14 2
9 14 7 5 6
5 7 5 2 7
4 5 13 5 6
*/

Compilation message

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i=0; i<ch.size(); i++) if (ch[i]!=ch[i-1]) {
      |                   ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 1 ms 896 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 2 ms 1024 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 2 ms 1024 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 1024 KB Output is correct
20 Correct 1 ms 896 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 1 ms 896 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 2 ms 1024 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 2 ms 1024 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 9 ms 2936 KB Output is correct
18 Correct 7 ms 2936 KB Output is correct
19 Correct 10 ms 2936 KB Output is correct
20 Correct 7 ms 2936 KB Output is correct
21 Correct 10 ms 2936 KB Output is correct
22 Correct 8 ms 2936 KB Output is correct
23 Correct 13 ms 2936 KB Output is correct
24 Correct 6 ms 2300 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 1024 KB Output is correct
28 Correct 1 ms 896 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 1 ms 896 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 2 ms 1024 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 2 ms 1024 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 9 ms 2936 KB Output is correct
18 Correct 7 ms 2936 KB Output is correct
19 Correct 10 ms 2936 KB Output is correct
20 Correct 7 ms 2936 KB Output is correct
21 Correct 10 ms 2936 KB Output is correct
22 Correct 8 ms 2936 KB Output is correct
23 Correct 13 ms 2936 KB Output is correct
24 Correct 6 ms 2300 KB Output is correct
25 Correct 60 ms 8696 KB Output is correct
26 Correct 51 ms 8696 KB Output is correct
27 Correct 50 ms 8696 KB Output is correct
28 Correct 71 ms 8692 KB Output is correct
29 Correct 50 ms 8692 KB Output is correct
30 Correct 71 ms 8692 KB Output is correct
31 Correct 49 ms 8692 KB Output is correct
32 Correct 70 ms 8688 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 1024 KB Output is correct
36 Correct 1 ms 896 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 1 ms 896 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 2 ms 1024 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 2 ms 1024 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 9 ms 2936 KB Output is correct
18 Correct 7 ms 2936 KB Output is correct
19 Correct 10 ms 2936 KB Output is correct
20 Correct 7 ms 2936 KB Output is correct
21 Correct 10 ms 2936 KB Output is correct
22 Correct 8 ms 2936 KB Output is correct
23 Correct 13 ms 2936 KB Output is correct
24 Correct 6 ms 2300 KB Output is correct
25 Correct 60 ms 8696 KB Output is correct
26 Correct 51 ms 8696 KB Output is correct
27 Correct 50 ms 8696 KB Output is correct
28 Correct 71 ms 8692 KB Output is correct
29 Correct 50 ms 8692 KB Output is correct
30 Correct 71 ms 8692 KB Output is correct
31 Correct 49 ms 8692 KB Output is correct
32 Correct 70 ms 8688 KB Output is correct
33 Correct 770 ms 89000 KB Output is correct
34 Correct 447 ms 88984 KB Output is correct
35 Correct 476 ms 88892 KB Output is correct
36 Correct 524 ms 89016 KB Output is correct
37 Correct 1795 ms 88924 KB Output is correct
38 Correct 1760 ms 88892 KB Output is correct
39 Correct 1816 ms 89016 KB Output is correct
40 Correct 1461 ms 87456 KB Output is correct
41 Correct 434 ms 88984 KB Output is correct
42 Correct 450 ms 88892 KB Output is correct
43 Correct 622 ms 88984 KB Output is correct
44 Correct 670 ms 88928 KB Output is correct
45 Correct 326 ms 50384 KB Output is correct
46 Correct 321 ms 44692 KB Output is correct
47 Correct 586 ms 88984 KB Output is correct
48 Correct 603 ms 88984 KB Output is correct
49 Correct 0 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 1 ms 1024 KB Output is correct
52 Correct 1 ms 896 KB Output is correct
53 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1676 KB Output is correct
2 Correct 8 ms 1676 KB Output is correct
3 Correct 5 ms 1656 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 7 ms 1656 KB Output is correct
6 Correct 7 ms 1656 KB Output is correct
7 Correct 7 ms 1656 KB Output is correct
8 Correct 7 ms 1656 KB Output is correct
9 Correct 7 ms 1656 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 5 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2727 ms 598564 KB Output is correct
3 Runtime error 1688 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 1 ms 896 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 2 ms 1024 KB Output is correct
11 Correct 2 ms 1024 KB Output is correct
12 Correct 2 ms 1024 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 9 ms 2936 KB Output is correct
18 Correct 7 ms 2936 KB Output is correct
19 Correct 10 ms 2936 KB Output is correct
20 Correct 7 ms 2936 KB Output is correct
21 Correct 10 ms 2936 KB Output is correct
22 Correct 8 ms 2936 KB Output is correct
23 Correct 13 ms 2936 KB Output is correct
24 Correct 6 ms 2300 KB Output is correct
25 Correct 60 ms 8696 KB Output is correct
26 Correct 51 ms 8696 KB Output is correct
27 Correct 50 ms 8696 KB Output is correct
28 Correct 71 ms 8692 KB Output is correct
29 Correct 50 ms 8692 KB Output is correct
30 Correct 71 ms 8692 KB Output is correct
31 Correct 49 ms 8692 KB Output is correct
32 Correct 70 ms 8688 KB Output is correct
33 Correct 770 ms 89000 KB Output is correct
34 Correct 447 ms 88984 KB Output is correct
35 Correct 476 ms 88892 KB Output is correct
36 Correct 524 ms 89016 KB Output is correct
37 Correct 1795 ms 88924 KB Output is correct
38 Correct 1760 ms 88892 KB Output is correct
39 Correct 1816 ms 89016 KB Output is correct
40 Correct 1461 ms 87456 KB Output is correct
41 Correct 434 ms 88984 KB Output is correct
42 Correct 450 ms 88892 KB Output is correct
43 Correct 622 ms 88984 KB Output is correct
44 Correct 670 ms 88928 KB Output is correct
45 Correct 326 ms 50384 KB Output is correct
46 Correct 321 ms 44692 KB Output is correct
47 Correct 586 ms 88984 KB Output is correct
48 Correct 603 ms 88984 KB Output is correct
49 Correct 10 ms 1676 KB Output is correct
50 Correct 8 ms 1676 KB Output is correct
51 Correct 5 ms 1656 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 7 ms 1656 KB Output is correct
54 Correct 7 ms 1656 KB Output is correct
55 Correct 7 ms 1656 KB Output is correct
56 Correct 7 ms 1656 KB Output is correct
57 Correct 7 ms 1656 KB Output is correct
58 Correct 2 ms 768 KB Output is correct
59 Correct 5 ms 1148 KB Output is correct
60 Correct 1 ms 512 KB Output is correct
61 Correct 2727 ms 598564 KB Output is correct
62 Runtime error 1688 ms 1048580 KB Execution killed with signal 9
63 Halted 0 ms 0 KB -