Submission #280503

# Submission time Handle Problem Language Result Execution time Memory
280503 2020-08-22T20:50:47 Z CaroLinda Rectangles (IOI19_rect) C++14
72 / 100
5000 ms 1048576 KB
#include <bits/stdc++.h>
#include "rect.h"

#define sz(x) (int)x.size()
#define mkt make_tuple
#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define ff first
#define ss second
#define eb emplace_back
#define ll long long
#define mk make_pair
#define pii pair<int,int>
#define debug printf
#define all(x) x.begin(),x.end()

const int MAXN = 2510 ;

using namespace std ;

int N , M ;

void solve( vector< vector<int > > &grid, vector< vector< vector<pii> > > &toPut )
{

    int tamLinha = sz( grid[0] ) ;
    vector<int> esq(tamLinha) , dir(tamLinha) , getFreq( tamLinha ) , lastVisit(tamLinha) ;

    for(int i = 1 ; i < sz(grid) - 1 ; i++ )
    {

        for(int j = tamLinha - 1 ; j >= 0 ; j-- )
            esq[j] = dir[j] = -1 ;

        set<pii> s ;

        for(int j = tamLinha - 2;  j >= 0 ; j-- )
        {

            int x = j+1 ;

            while( x != -1 && grid[i][x]<= grid[i][j] )
                x = dir[x] ;

            dir[j] = x ;

        }

        for(int j = 1 ; j <  tamLinha ; j++ )
        {

            int x = j-1 ;

            while(x != -1 && grid[i][x] <= grid[i][j] )
                x = esq[x] ;

            esq[j] = x ;

        }

        lp(j,1,tamLinha-1)
            if( esq[j] != -1 && dir[j] != -1 && s.find(mk( esq[j] , dir[j] )) == s.end() )
            {
                toPut[ i ][ esq[j]+1 ].emplace_back( mk(dir[j]-1 , i) ) ;
                s.insert( mk(esq[j] , dir[j]) ) ;
            }

    }

   for(int j = 1 ; j < tamLinha ; j++ )
    {
        lp(i,0,tamLinha) getFreq[i] = lastVisit[i] = -1 ;

        for(int i = sz(grid) - 2 ; i >= 1 ; i-- )
            for(auto &e : toPut[i][j] )
            {
                if(  lastVisit[e.ff] != i+1 ) getFreq[e.ff] = i ;
                e.ss = getFreq[e.ff] ;
                lastVisit[e.ff] = i ;
            }
    }

}

ll count_rectangles( vector<vector<int> > mat )
{
    N = sz(mat) ;
    M = sz( mat[0] ) ;

    vector< vector<int> > gridCerto , gridRota ;
    vector< vector< vector<pii> > > auxCerto, auxRota ;
    lp(i,0,N)
    {
        gridCerto.emplace_back(*(new vector<int>)) ;
        auxCerto.emplace_back(*(new vector< vector<pii> >)) ;
        lp(j,0,M)
        {
            gridCerto[i].emplace_back( mat[i][j] ) ;
            auxCerto[i].emplace_back( *(new vector<pii>) ) ;
        }
    }
    lp(i,0,M)
    {
        gridRota.emplace_back( *(new vector<int>) ) ;
        auxRota.emplace_back(*(new vector< vector<pii> >)) ;
        lp(j,0,N)
        {
            gridRota[i].emplace_back( mat[j][i] ) ;
            auxRota[i].emplace_back( *(new vector<pii>) ) ;
        }
    }

    solve(gridCerto, auxCerto ) ;
    solve( gridRota, auxRota  );

   /* lp(i,1,N-1)
    {
        lp(j,1,M-1)
        {
            printf("Na casinha %d %d -> " , i , j ) ;
            for(auto e : auxCerto[i][j] ) printf("%d %d, " , e.ff, e.ss ) ;
            printf("\n") ;
        }
    } */

    ll ans = 0LL ;

    lp(i,1,N-1)
        lp(j,1,M-1)
        {
            for(auto e : auxCerto[i][j] )
                for(auto ee : auxRota[j][i] )
                    ans += ( ee.ss >= e.ff && e.ss >= ee.ff ) ;
        }

    return ans ;

}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 4 ms 1792 KB Output is correct
18 Correct 5 ms 1792 KB Output is correct
19 Correct 5 ms 1792 KB Output is correct
20 Correct 3 ms 1536 KB Output is correct
21 Correct 6 ms 1536 KB Output is correct
22 Correct 5 ms 1664 KB Output is correct
23 Correct 5 ms 1664 KB Output is correct
24 Correct 3 ms 928 KB Output is correct
25 Correct 0 ms 256 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 4 ms 1792 KB Output is correct
18 Correct 5 ms 1792 KB Output is correct
19 Correct 5 ms 1792 KB Output is correct
20 Correct 3 ms 1536 KB Output is correct
21 Correct 6 ms 1536 KB Output is correct
22 Correct 5 ms 1664 KB Output is correct
23 Correct 5 ms 1664 KB Output is correct
24 Correct 3 ms 928 KB Output is correct
25 Correct 27 ms 8704 KB Output is correct
26 Correct 27 ms 8696 KB Output is correct
27 Correct 32 ms 8824 KB Output is correct
28 Correct 17 ms 6912 KB Output is correct
29 Correct 28 ms 7680 KB Output is correct
30 Correct 31 ms 7800 KB Output is correct
31 Correct 36 ms 7680 KB Output is correct
32 Correct 28 ms 7672 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 4 ms 1792 KB Output is correct
18 Correct 5 ms 1792 KB Output is correct
19 Correct 5 ms 1792 KB Output is correct
20 Correct 3 ms 1536 KB Output is correct
21 Correct 6 ms 1536 KB Output is correct
22 Correct 5 ms 1664 KB Output is correct
23 Correct 5 ms 1664 KB Output is correct
24 Correct 3 ms 928 KB Output is correct
25 Correct 27 ms 8704 KB Output is correct
26 Correct 27 ms 8696 KB Output is correct
27 Correct 32 ms 8824 KB Output is correct
28 Correct 17 ms 6912 KB Output is correct
29 Correct 28 ms 7680 KB Output is correct
30 Correct 31 ms 7800 KB Output is correct
31 Correct 36 ms 7680 KB Output is correct
32 Correct 28 ms 7672 KB Output is correct
33 Correct 227 ms 88184 KB Output is correct
34 Correct 197 ms 83192 KB Output is correct
35 Correct 198 ms 83320 KB Output is correct
36 Correct 299 ms 78444 KB Output is correct
37 Correct 364 ms 103680 KB Output is correct
38 Correct 370 ms 103552 KB Output is correct
39 Correct 355 ms 103928 KB Output is correct
40 Correct 328 ms 97784 KB Output is correct
41 Correct 176 ms 78200 KB Output is correct
42 Correct 218 ms 80760 KB Output is correct
43 Correct 400 ms 89336 KB Output is correct
44 Correct 407 ms 91512 KB Output is correct
45 Correct 192 ms 47224 KB Output is correct
46 Correct 201 ms 47224 KB Output is correct
47 Correct 417 ms 89080 KB Output is correct
48 Correct 372 ms 90104 KB Output is correct
49 Correct 0 ms 256 KB Output is correct
50 Correct 1 ms 256 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1920 KB Output is correct
2 Correct 8 ms 1664 KB Output is correct
3 Correct 12 ms 1792 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 11 ms 1920 KB Output is correct
6 Correct 11 ms 1920 KB Output is correct
7 Correct 12 ms 1920 KB Output is correct
8 Correct 10 ms 1920 KB Output is correct
9 Correct 11 ms 1920 KB Output is correct
10 Correct 8 ms 1024 KB Output is correct
11 Correct 13 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1177 ms 432480 KB Output is correct
3 Correct 2732 ms 931956 KB Output is correct
4 Correct 2640 ms 936924 KB Output is correct
5 Correct 2711 ms 936980 KB Output is correct
6 Correct 659 ms 422008 KB Output is correct
7 Correct 1388 ms 786744 KB Output is correct
8 Correct 1464 ms 837444 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 4 ms 1792 KB Output is correct
18 Correct 5 ms 1792 KB Output is correct
19 Correct 5 ms 1792 KB Output is correct
20 Correct 3 ms 1536 KB Output is correct
21 Correct 6 ms 1536 KB Output is correct
22 Correct 5 ms 1664 KB Output is correct
23 Correct 5 ms 1664 KB Output is correct
24 Correct 3 ms 928 KB Output is correct
25 Correct 27 ms 8704 KB Output is correct
26 Correct 27 ms 8696 KB Output is correct
27 Correct 32 ms 8824 KB Output is correct
28 Correct 17 ms 6912 KB Output is correct
29 Correct 28 ms 7680 KB Output is correct
30 Correct 31 ms 7800 KB Output is correct
31 Correct 36 ms 7680 KB Output is correct
32 Correct 28 ms 7672 KB Output is correct
33 Correct 227 ms 88184 KB Output is correct
34 Correct 197 ms 83192 KB Output is correct
35 Correct 198 ms 83320 KB Output is correct
36 Correct 299 ms 78444 KB Output is correct
37 Correct 364 ms 103680 KB Output is correct
38 Correct 370 ms 103552 KB Output is correct
39 Correct 355 ms 103928 KB Output is correct
40 Correct 328 ms 97784 KB Output is correct
41 Correct 176 ms 78200 KB Output is correct
42 Correct 218 ms 80760 KB Output is correct
43 Correct 400 ms 89336 KB Output is correct
44 Correct 407 ms 91512 KB Output is correct
45 Correct 192 ms 47224 KB Output is correct
46 Correct 201 ms 47224 KB Output is correct
47 Correct 417 ms 89080 KB Output is correct
48 Correct 372 ms 90104 KB Output is correct
49 Correct 16 ms 1920 KB Output is correct
50 Correct 8 ms 1664 KB Output is correct
51 Correct 12 ms 1792 KB Output is correct
52 Correct 0 ms 256 KB Output is correct
53 Correct 11 ms 1920 KB Output is correct
54 Correct 11 ms 1920 KB Output is correct
55 Correct 12 ms 1920 KB Output is correct
56 Correct 10 ms 1920 KB Output is correct
57 Correct 11 ms 1920 KB Output is correct
58 Correct 8 ms 1024 KB Output is correct
59 Correct 13 ms 1408 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1177 ms 432480 KB Output is correct
62 Correct 2732 ms 931956 KB Output is correct
63 Correct 2640 ms 936924 KB Output is correct
64 Correct 2711 ms 936980 KB Output is correct
65 Correct 659 ms 422008 KB Output is correct
66 Correct 1388 ms 786744 KB Output is correct
67 Correct 1464 ms 837444 KB Output is correct
68 Correct 3540 ms 1048576 KB Output is correct
69 Correct 3139 ms 1005592 KB Output is correct
70 Correct 3125 ms 1005508 KB Output is correct
71 Execution timed out 5116 ms 933280 KB Time limit exceeded
72 Halted 0 ms 0 KB -