제출 #400793

#제출 시각아이디문제언어결과실행 시간메모리
400793mosiashvililukaRectangles (IOI19_rect)C++17
100 / 100
1788 ms174260 KiB
#include "rect.h" #include<bits/stdc++.h> using namespace std; int a,b,c,d,e,i,j,ii,jj,zx,xc,f[2509][2509],pas; short lf[2509][2509],rg[2509][2509],zm[2509][2509],qv[2509][2509]; short ZM[2509][2509],RG[2509][2509],QV[2509][2509],LF[2509][2509]; stack <int> st; void chk(int q, int w, int qq, int ww){ if(q>qq||w>ww) return; if(q<=1||w<=1||qq>=a||ww>=b) return; if(rg[q][w-1]==ww+1){ if(RG[q][w-1]<qq){ return; } }else{ if(lf[q][ww+1]==w-1){ if(LF[q][ww+1]<qq){ return; } }else{ return; } } if(zm[q-1][w]==qq+1){ if(ZM[q-1][w]<ww){ return; } }else{ if(qv[qq+1][w]==q-1){ if(QV[qq+1][w]<ww){ return; } }else{ return; } } pas++; } long long count_rectangles(std::vector<std::vector<int> > VA) { a=VA.size(); b=VA[0].size(); if(a<3||b<3){ return 0; } for(i=1; i<=a; i++){ for(j=1; j<=b; j++){ f[i][j]=VA[i-1][j-1]; } } for(i=1; i<=a; i++){ while(st.size()) st.pop(); for(j=1; j<=b; j++){ while(st.size()&&f[i][st.top()]<f[i][j]){ st.pop(); } if(st.size()){ lf[i][j]=st.top(); } st.push(j); } while(st.size()) st.pop(); for(j=b; j>=1; j--){ while(st.size()&&f[i][st.top()]<f[i][j]){ st.pop(); } if(st.size()){ if(f[i][st.top()]!=f[i][j]) rg[i][j]=st.top(); } st.push(j); } } for(j=1; j<=b; j++){ while(st.size()) st.pop(); for(i=1; i<=a; i++){ while(st.size()&&f[st.top()][j]<f[i][j]){ st.pop(); } if(st.size()){ qv[i][j]=st.top(); } st.push(i); } while(st.size()) st.pop(); for(i=a; i>=1; i--){ while(st.size()&&f[st.top()][j]<f[i][j]){ st.pop(); } if(st.size()){ if(f[st.top()][j]!=f[i][j]) zm[i][j]=st.top(); } st.push(i); } } for(j=b; j>=1; j--){ for(i=1; i<=a; i++){ if(qv[i][j]!=0){ if(qv[i][j+1]==qv[i][j]){ QV[i][j]=QV[i][j+1]; }else{ if(zm[qv[i][j]][j+1]==i){ QV[i][j]=ZM[qv[i][j]][j+1]; }else{ QV[i][j]=j; } } } if(zm[i][j]!=0){ if(zm[i][j+1]==zm[i][j]){ ZM[i][j]=ZM[i][j+1]; }else{ if(qv[zm[i][j]][j+1]==i){ ZM[i][j]=QV[zm[i][j]][j+1]; }else{ ZM[i][j]=j; } } } } } for(i=a; i>=1; i--){ for(j=1; j<=b; j++){ if(lf[i][j]!=0){ if(lf[i+1][j]==lf[i][j]){ LF[i][j]=LF[i+1][j]; }else{ if(rg[i+1][lf[i][j]]==j){ LF[i][j]=RG[i+1][lf[i][j]]; }else{ LF[i][j]=i; } } } if(rg[i][j]!=0){ if(rg[i+1][j]==rg[i][j]){ RG[i][j]=RG[i+1][j]; }else{ if(lf[i+1][rg[i][j]]==j){ RG[i][j]=LF[i+1][rg[i][j]]; }else{ RG[i][j]=i; } } } } } // for(i=2; i<a; i++){ for(j=2; j<b; j++){ if(zm[i-1][j]!=0&&rg[i][j-1]!=0){ chk(i,j,zm[i-1][j]-1,rg[i][j-1]-1); } if(qv[i+1][j]!=0&&rg[i][j-1]!=0){ chk(qv[i+1][j]+1,j,i,rg[i][j-1]-1); } if(rg[i][j-1]!=0){ jj=rg[i][j-1]-1; if(zm[i-1][jj]!=0){ chk(i,j,zm[i-1][jj]-1,jj); } if(qv[i+1][jj]!=0){ chk(qv[i+1][jj]+1,j,i,jj); } } // if(zm[i-1][j]!=0&&lf[i][j+1]!=0){ chk(i,lf[i][j+1]+1,zm[i-1][j]-1,j); } if(qv[i+1][j]!=0&&lf[i][j+1]!=0){ chk(qv[i+1][j]+1,lf[i][j+1]+1,i,j); } if(lf[i][j+1]!=0){ jj=lf[i][j+1]+1; if(zm[i-1][jj]!=0){ chk(i,jj,zm[i-1][jj]-1,j); } if(qv[i+1][jj]!=0){ chk(qv[i+1][jj]+1,jj,i,j); } } } } pas/=2; return pas; } /*int main(){ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>a>>b; vector <int> QA; vector <vector <int> > WA; for(i=1; i<=a; i++){ QA.clear(); for(j=1; j<=b; j++){ cin>>c; QA.push_back(c); } WA.push_back(QA); } cout<<count_rectangles(WA); return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...