Submission #293143

# Submission time Handle Problem Language Result Execution time Memory
293143 2020-09-07T16:48:04 Z CaroLinda Furniture (JOI20_furniture) C++14
100 / 100
857 ms 117368 KB
#include <bits/stdc++.h>

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

const int MAXN = 1010 ;
const int MAX = 1e6+100;

using namespace std ;

int N , M , Q ;
int qtdDist[ MAXN*3 ] ;
int grid[MAXN][MAXN] ;
vector<int> adj[MAX] , revAdj[MAX] ;
bool isOn[MAX] ;

int code(int i, int j) { return i*M + j ; }
bool valid(int i, int j) { return 0 <= min(i,j) && i < N && j < M ; }

void desliga(int x)
{
    if(!isOn[x]) return ;

    vector<int> fila ;

    //Desligando adj
    for(auto e : adj[x] )
    {
        if( x == revAdj[e][0] && sz(revAdj[e]) > 1 )  swap( revAdj[e][0] , revAdj[e][1] ) ;
        revAdj[e].pop_back() ;

        if( sz(revAdj[e]) == 0 ) fila.pb(e) ;

    }

    //Desligando revAdj
    for(auto e : revAdj[x])
    {
        if( x == adj[e][0] && sz(adj[e]) > 1 ) swap( adj[e][0] , adj[e][1] ) ;
        adj[e].pop_back() ;

        if( sz(adj[e]) == 0 ) fila.pb(e) ;

    }

    isOn[x] = false ;
    adj[x].clear() ;
    revAdj[x].clear() ;

    int i = x/M ;
    int j = x%M ;

    qtdDist[ i + j ]-- ;

    for(int i : fila )
        if( isOn[i] ) desliga(i) ;

}

int main()
{
    scanf("%d%d", &N , &M ) ;
    lp(i,0,N)
        lp(j,0,M)
        {
            scanf("%d", &grid[i][j] ) ;

            isOn[ code(i,j) ] = true ;
            qtdDist[ i + j ]++ ;

            int viz0 = -1, viz1 = -1, viz2 = -1, viz3 = -1 ;
            int idx = code(i,j) ;

            if( valid(i-1,j) ) viz0 = code(i-1,j) ;
            if( valid(i,j+1) ) viz1 = code(i,j+1) ;
            if( valid(i+1, j) ) viz2 = code(i+1,j) ;
            if( valid(i,j-1) ) viz3 = code(i,j-1) ;

            if( viz0 != -1 ) revAdj[ idx ].pb( viz0 ) ;
            if( viz3 != -1 ) revAdj[idx].pb( viz3 ) ;
            if( viz1 != -1 ) adj[idx].pb( viz1 ) ;
            if( viz2 != -1 ) adj[idx].pb( viz2 ) ;

        }

    lp(i,0,N)
        lp(j,0,M)
            if( grid[i][j] == 1 ) desliga(code(i,j)) ;

    scanf("%d", &Q ) ;


    for(int i = 1 , x , y ; i <= Q ; i++ )
    {
        scanf("%d%d", &x, &y ) ;
        x-- , y-- ;

        if( qtdDist[x+y] == 1 && isOn[ code(x,y) ] )
        {
            printf("0\n") ;
            continue ;
        }

        desliga(code(x,y)) ;
        printf("1\n") ;

    }

}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |     scanf("%d%d", &N , &M ) ;
      |     ~~~~~^~~~~~~~~~~~~~~~~~
furniture.cpp:74:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |             scanf("%d", &grid[i][j] ) ;
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~
furniture.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   98 |     scanf("%d", &Q ) ;
      |     ~~~~~^~~~~~~~~~~
furniture.cpp:103:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  103 |         scanf("%d%d", &x, &y ) ;
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 47984 KB Output is correct
2 Correct 35 ms 48000 KB Output is correct
3 Correct 38 ms 48176 KB Output is correct
4 Correct 41 ms 48352 KB Output is correct
5 Correct 41 ms 48376 KB Output is correct
6 Correct 42 ms 48412 KB Output is correct
7 Correct 40 ms 48376 KB Output is correct
8 Correct 40 ms 48412 KB Output is correct
9 Correct 41 ms 48376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 47984 KB Output is correct
2 Correct 35 ms 48000 KB Output is correct
3 Correct 38 ms 48176 KB Output is correct
4 Correct 41 ms 48352 KB Output is correct
5 Correct 41 ms 48376 KB Output is correct
6 Correct 42 ms 48412 KB Output is correct
7 Correct 40 ms 48376 KB Output is correct
8 Correct 40 ms 48412 KB Output is correct
9 Correct 41 ms 48376 KB Output is correct
10 Correct 68 ms 51204 KB Output is correct
11 Correct 39 ms 48120 KB Output is correct
12 Correct 720 ms 112216 KB Output is correct
13 Correct 423 ms 106884 KB Output is correct
14 Correct 857 ms 109388 KB Output is correct
15 Correct 820 ms 106540 KB Output is correct
16 Correct 748 ms 111656 KB Output is correct
17 Correct 799 ms 115192 KB Output is correct
18 Correct 838 ms 113272 KB Output is correct
19 Correct 763 ms 117368 KB Output is correct
20 Correct 822 ms 117068 KB Output is correct
21 Correct 788 ms 117240 KB Output is correct