답안 #734145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734145 2023-05-01T22:55:24 Z n0sk1ll Furniture (JOI20_furniture) C++17
100 / 100
290 ms 13900 KB
#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;







//Note to self: Check for overflow

bool c1[1003][1003]; //blokiran za gornji levi cosak?
bool c2[1003][1003]; //blokiran za dodnji desni cosak?
int slob[2006]; //koliko slobodnih na datoj dijagonali

void Put1(int x, int y)
{
    if (c1[x][y]) return;
    if (!c2[x][y]) slob[x+y]--;

    c1[x][y]=1;

    if (c1[x-1][y+1]) Put1(x,y+1);
    if (c1[x+1][y-1]) Put1(x+1,y);
}

void Put2(int x, int y)
{
    if (c2[x][y]) return;
    if (!c1[x][y]) slob[x+y]--;

    c2[x][y]=1;

    if (c2[x-1][y+1]) Put2(x-1,y);
    if (c2[x+1][y-1]) Put2(x,y-1);
}

int main()
{
    FAST;

    int n,m; cin>>n>>m;
    fff(i,0,n+1) fff(j,0,m+1) c1[i][j]=1,c2[i][j]=1;
    fff(i,1,n) fff(j,1,m) slob[i+j]++,c1[i][j]=0,c2[i][j]=0;
    fff(i,1,n) fff(j,1,m)
    {
        bool sta; cin>>sta;
        if (sta) Put1(i,j),Put2(i,j);
    }

    int q; cin>>q;
    while (q--)
    {
        int x,y; cin>>x>>y;
        if (c1[x][y] || c2[x][y] || slob[x+y]>1) Put1(x,y),Put2(x,y),cout<<1<<"\n";
        else cout<<0<<"\n";
    }
}

//Note to self: Check for overflow
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 3 ms 572 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 3 ms 572 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 12 ms 724 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 131 ms 7028 KB Output is correct
13 Correct 59 ms 4032 KB Output is correct
14 Correct 235 ms 11612 KB Output is correct
15 Correct 259 ms 11872 KB Output is correct
16 Correct 247 ms 12748 KB Output is correct
17 Correct 263 ms 13496 KB Output is correct
18 Correct 251 ms 13064 KB Output is correct
19 Correct 290 ms 13772 KB Output is correct
20 Correct 265 ms 13900 KB Output is correct
21 Correct 274 ms 13896 KB Output is correct