답안 #516473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516473 2022-01-21T11:29:03 Z terrasphere Furniture (JOI20_furniture) C++17
5 / 100
5000 ms 7212 KB
#include <bits/stdc++.h>

using namespace std;

int arr[1111][1111];
int n,m;
bool visited[1111][1111];

queue<pair<int,int>> que;

bool possible()
{
    memset(visited,false,sizeof(visited));
    que.push({1,1});
    while(!que.empty())
    {
        pair<int,int> c;
        c=que.front();
        que.pop();
        if(c.first==n && c.second==m)
            return true;
        if(c.second+1<=m && arr[c.first][c.second+1]==0 && !visited[c.first][c.second+1])
        {
            que.push({c.first,c.second+1});
            visited[c.first][c.second+1]=true;
        }
        if(c.first+1<=n && arr[c.first+1][c.second]==0 && !visited[c.first+1][c.second])
        {
            que.push({c.first+1,c.second});
            visited[c.first+1][c.second]=true;
        }
    }
    return false;
}

int main()
{
    int q;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&arr[i][j]);
    scanf("%d",&q);
    for(int i=1;i<=q;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        if(arr[a][b]==1)
        {
            printf("0\n");
            continue;
        }
        arr[a][b]=1;
        if(possible())
            printf("1\n");
        else
        {
            printf("0\n");
            arr[a][b]=0;
        }
    }
    return 0;
}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
furniture.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |             scanf("%d",&arr[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~
furniture.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
furniture.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1740 KB Output is correct
2 Correct 121 ms 1932 KB Output is correct
3 Correct 212 ms 1924 KB Output is correct
4 Correct 408 ms 1968 KB Output is correct
5 Correct 438 ms 2132 KB Output is correct
6 Correct 557 ms 2020 KB Output is correct
7 Correct 439 ms 2128 KB Output is correct
8 Correct 462 ms 1996 KB Output is correct
9 Correct 691 ms 2004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1740 KB Output is correct
2 Correct 121 ms 1932 KB Output is correct
3 Correct 212 ms 1924 KB Output is correct
4 Correct 408 ms 1968 KB Output is correct
5 Correct 438 ms 2132 KB Output is correct
6 Correct 557 ms 2020 KB Output is correct
7 Correct 439 ms 2128 KB Output is correct
8 Correct 462 ms 1996 KB Output is correct
9 Correct 691 ms 2004 KB Output is correct
10 Correct 4916 ms 2064 KB Output is correct
11 Correct 363 ms 1764 KB Output is correct
12 Execution timed out 5019 ms 7212 KB Time limit exceeded
13 Halted 0 ms 0 KB -