답안 #1084118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1084118 2024-09-05T08:33:50 Z Boycl07 Furniture (JOI20_furniture) C++17
100 / 100
187 ms 15956 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "BAI1"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }

inline int readInt()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll  n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}

const int N = 1e3 + 3;
const int M = 1e3 + 3;
const int LOG = 50;
const int MOD = 1e9 + 7;
const ll INF = 1e18;

int n, m, q;

int c[N][N];

int cnt[2 * N];


void try_(int x, int y)
{
    if(!c[x][y])
    {
        --cnt[x + y];
        c[x][y] = 1;
        if(c[x + 1][y - 1])
        {
            if(!c[x + 1][y]) try_(x + 1, y);
            if(!c[x][y - 1]) try_(x, y - 1);
        }
        if(c[x - 1][y + 1])
        {
            if(!c[x][y + 1]) try_(x, y + 1);
            if(!c[x - 1][y]) try_(x - 1, y);
        }
    }
}

void solve()
{
    cin >> n >> m;
    forn(i, 0, n) c[i][0] = c[i][m + 1] = 1;
    forn(i, 0, m) c[0][i] = c[n + 1][i] = 1;
    rep(i, n) rep(j, m) ++cnt[i + j];
    rep(i, n) rep(j, m)
    {
        int x;
        cin >> x;
        if(x) try_(i, j);
    }
    cin >> q;
    rep(i, q)
    {
        int x, y;
        cin >> x >> y;
        if(c[x][y]) cout << 1 << endl;
        else
        {
            if(cnt[x + y] > 1) try_(x, y), cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int TC = 1;

    if(fopen("note.inp", "r"))
    {
        freopen("note.inp", "r", stdin);
        freopen("note.out", "w", stdout);
    }

    while(TC--)
    {
        solve();
        cout << endl;
    }

    return 0;
}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen("note.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
furniture.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen("note.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 3 ms 956 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 4 ms 992 KB Output is correct
9 Correct 3 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 3 ms 956 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 4 ms 992 KB Output is correct
9 Correct 3 ms 860 KB Output is correct
10 Correct 6 ms 860 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 82 ms 9036 KB Output is correct
13 Correct 36 ms 5980 KB Output is correct
14 Correct 151 ms 13548 KB Output is correct
15 Correct 151 ms 13904 KB Output is correct
16 Correct 160 ms 14676 KB Output is correct
17 Correct 172 ms 15440 KB Output is correct
18 Correct 171 ms 15180 KB Output is correct
19 Correct 187 ms 15836 KB Output is correct
20 Correct 170 ms 15952 KB Output is correct
21 Correct 173 ms 15956 KB Output is correct