제출 #400790

#제출 시각아이디문제언어결과실행 시간메모리
400790mosiashvililukaRectangles (IOI19_rect)C++17
100 / 100
1848 ms220388 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 lf1[2509][2509],lf2[2509][2509]; short rg1[2509][2509],rg2[2509][2509]; short zm1[2509][2509],zm2[2509][2509]; short qv1[2509][2509],qv2[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; //cout<<q<<" "<<w<<" "<<qq<<" "<<ww<<endl; //cout<<lf[q][w-1]<<endl; 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=1; j<=b; j++){ for(i=1; i<=a; i++){ if(lf[i][j]==lf[i-1][j]){ lf1[i][j]=lf1[i-1][j]+1; }else{ lf1[i][j]=1; } if(rg[i][j]==rg[i-1][j]){ rg1[i][j]=rg1[i-1][j]+1; }else{ rg1[i][j]=1; } } for(i=a; i>=1; i--){ if(lf[i][j]==lf[i+1][j]){ lf2[i][j]=lf2[i+1][j]+1; }else{ lf2[i][j]=1; } if(rg[i][j]==rg[i+1][j]){ rg2[i][j]=rg2[i+1][j]+1; }else{ rg2[i][j]=1; } } } for(i=1; i<=a; i++){ for(j=1; j<=b; j++){ if(qv[i][j]==qv[i][j-1]){ qv1[i][j]=qv1[i][j-1]+1; }else{ qv1[i][j]=1; } if(zm[i][j]==zm[i][j-1]){ zm1[i][j]=zm1[i][j-1]+1; }else{ zm1[i][j]=1; } } for(j=b; j>=1; j--){ if(qv[i][j]==qv[i][j+1]){ qv2[i][j]=qv2[i][j+1]+1; }else{ qv2[i][j]=1; } if(zm[i][j]==zm[i][j+1]){ zm2[i][j]=zm2[i][j+1]+1; }else{ zm2[i][j]=1; } } }*/ // 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; }
#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...