Submission #423570

#TimeUsernameProblemLanguageResultExecution timeMemory
423570KerimFurniture (JOI20_furniture)C++17
100 / 100
488 ms15756 KiB
#include "bits/stdc++.h" #define MAXN 100009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N=1002; int vis[N][N],dgn[N+N],n,m; stack<PII>st; void upd(int x,int y){ if(!vis[x][y]){ dgn[x+y]--; vis[x][y]=1; st.push(mp(x,y)); } } void check(int x,int y){ if(vis[x][y] and vis[x+1][y-1]){ upd(x,y-1); upd(x+1,y); } } int mark(int x,int y){ if(vis[x][y])return 1; if(dgn[x+y]==1)return 0; upd(x,y); while(!st.empty()){ int x=st.top().ff; int y=st.top().ss; st.pop(); check(x-1,y+1); check(x,y); } return 1; } int main(){ //~ freopen("file.in", "r", stdin); scanf("%d%d",&n,&m); for(int i=0;i<=n+1;i++) for(int j=0;j<=m+1;j++){ if(!j or !i or i>n or j>m)vis[i][j]=1; else dgn[i+j]++; } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ int x; scanf("%d",&x); if(x)assert(mark(i,j)); } int q; scanf("%d",&q); while(q--){ int x,y; scanf("%d%d",&x,&y); printf("%d\n",mark(x,y)); } return 0; }

Compilation message (stderr)

furniture.cpp: In function 'int main()':
furniture.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
furniture.cpp:60:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |    scanf("%d",&x);
      |    ~~~~~^~~~~~~~~
furniture.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
furniture.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...