답안 #1019541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019541 2024-07-11T03:24:38 Z cpptowin Furniture (JOI20_furniture) C++17
5 / 100
5000 ms 18204 KB
#include<bits/stdc++.h>
#define fo(i,l,r) for(int i = l ; i <= r ; i++)
#define fod(i,r,l) for(int i = r ; i >= l ; i--)
#define pb emplace_back
#define maxn 1000010
#define N 1010
#define int long long
#define ss(x) (int) x.size()
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vii vector<pii>
#define en cout << "\n";
#define bit(x,i) ((x >> i) & 1)
#define bitcount(x) __builtint_popcount(x)
#define onbit(x,i) (x | (1ll << i))
#define offbit(x,i) (x ^ (1ll << i))
#define inf (int)1e18
#define lb(x) x & (-x)
using namespace std;
int n,m,q;
int a[N][N],r[N][N],cnt[maxn];
main()
{
#define name "TASK"
    if(fopen(name".inp","r"))
    {
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    fo(i,1,n) fo(j,1,m) cin >> a[i][j],r[i][j] = a[i][j];
    fo(i,1,n) fo(j,1,m) if(!r[i][j] and i * j != 1 and i * j != n * m)
    {
        bool ok = 1;
        if(i > 1 and !r[i - 1][j]) ok = 0;
        if(j > 1 and !r[i][j - 1]) ok = 0;
        r[i][j] = ok;
    }
    fod(i,n,1) fod(j,m,1) if(!r[i][j] and i * j != 1 and i * j != n * m)
    {
        bool ok = 1;
        if(i < n and !r[i + 1][j]) ok = 0;
        if(j < m and !r[i][j + 1]) ok = 0;
        r[i][j] = ok;
    }
    fo(i,1,n) fo(j,1,m) if(!r[i][j]) cnt[i + j]++;
    cin >> q;
    while(q--)
    {
        int i,j;
        cin >> i >> j;
        if(r[i][j] == 1) cout << 1 << "\n";
        else
        {
            if(cnt[i + j] > 1)
            {
                cout << 1 << "\n";
                r[i][j] = 1;
                cnt[i + j]--;
                fod(u,i,1) fod(v,j,1) if(!r[u][v])
                {
                    bool ok = 1;
                    if(u < n and !r[u + 1][v]) ok = 0;
                    if(v < m and !r[u][v + 1]) ok = 0;
                    r[u][v] = ok;
                    cnt[u + v] -= ok;
                }
                fo(u,i,n) fo(v,j,m) if(!r[u][v])
                {
                    bool ok = 1;
                    if(u > 1 and !r[u - 1][v]) ok = 0;
                    if(v > 1 and !r[u][v - 1]) ok = 0;
                    r[u][v] = ok;
                    cnt[u + v] -= ok;
                }
            }
            else  cout << 0 << "\n";
        }
    }
}

Compilation message

furniture.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main()
      | ^~~~
furniture.cpp: In function 'int main()':
furniture.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
furniture.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 7 ms 1116 KB Output is correct
4 Correct 10 ms 1324 KB Output is correct
5 Correct 14 ms 1372 KB Output is correct
6 Correct 22 ms 1372 KB Output is correct
7 Correct 4 ms 1372 KB Output is correct
8 Correct 6 ms 1368 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 7 ms 1116 KB Output is correct
4 Correct 10 ms 1324 KB Output is correct
5 Correct 14 ms 1372 KB Output is correct
6 Correct 22 ms 1372 KB Output is correct
7 Correct 4 ms 1372 KB Output is correct
8 Correct 6 ms 1368 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 10 ms 1624 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Execution timed out 5099 ms 18204 KB Time limit exceeded
13 Halted 0 ms 0 KB -