답안 #1093333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093333 2024-09-26T15:09:26 Z 8pete8 Furniture (JOI20_furniture) C++17
0 / 100
2 ms 11008 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=998244353,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m,q;
void setIO(string name){		
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);	
}
int grid[2002][2002],can[2002][2002],can2[2002][2002],yes[2002][2002];
int cnt[2002];
//0=l, 1=r
void update(int x,int y){
    if(x<=0||y<=0)return;
    if(!yes[x][y])return;
    if(grid[x][y]==0&&(yes[x+1][y]||yes[x][y+1]))return;
    yes[x][y]=0;
    cnt[x+y]--;
    update(x-1,y);
    update(x,y-1);
}
void update2(int x,int y){
    if(x>n||y>m)return;
    if(!yes[x][y])return;
    if(grid[x][y]==0&&(yes[x-1][y]||yes[x][y-1]))return;
    yes[x][y]=0;
    cnt[x+y]--;
    update(x+1,y);
    update(x,y+1);
}
int32_t main(){
    fastio
	cin>>n>>m;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>grid[i][j];
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
        if(i==1&&j==1)can[i][j]=1;
        if(grid[i][j])continue;
        can[i][j]|=(can[i-1][j]|can[i][j-1]);
    }
    for(int i=n;i>=1;i--)for(int j=m;j>=1;j--){
        if(i==n&&j==m)can2[i][j]=1;
        if(grid[i][j])continue;
        can2[i][j]|=(can2[i+1][j]|can2[i][j+1]);
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
        yes[i][j]=(can[i][j]&can2[i][j]);
        if(yes[i][j])cnt[i+j]++;
    }
    int q;cin>>q;
    while(q--){
        int x,y;cin>>x>>y;
        if(!yes[x][y])cout<<1<<'\n';
        else{
            if(cnt[x+y]>1){
                cout<<1<<'\n';
                grid[x][y]=1;
                cnt[x+y]++;
                update(x,y);
                yes[x][y]=1;
                update2(x,y);
            }
            else cout<<0<<'\n';
        }
    }
}
/*
*/

Compilation message

furniture.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
furniture.cpp:38:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   38 | void setIO(string name){
      |                       ^
furniture.cpp:46:24: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   46 | void update(int x,int y){
      |                        ^
furniture.cpp:55:25: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   55 | void update2(int x,int y){
      |                         ^
furniture.cpp:64:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   64 | int32_t main(){
      |              ^
furniture.cpp: In function 'void setIO(std::string)':
furniture.cpp:40:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
furniture.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Incorrect 2 ms 11008 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Incorrect 2 ms 11008 KB Output isn't correct
3 Halted 0 ms 0 KB -