제출 #969280

#제출 시각아이디문제언어결과실행 시간메모리
969280NemanjaSo2005Rectangles (IOI19_rect)C++17
72 / 100
5030 ms806608 KiB
#include "rect.h" #include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=2505; ll res=0; int N,M,mat[maxn][maxn]; int L[maxn],R[maxn]; stack<int> S; map<pair<int,int>,int> mapa[maxn]; vector<pair<int,int>> getinterval(vector<int> V){ vector<pair<int,int>> res; while(S.size()) S.pop(); S.push(0); L[0]=-1; for(int i=1;i<V.size();i++){ while(S.size()){ if(V[S.top()]>V[i]) break; S.pop(); } if(S.size()==0) L[i]=-1; else L[i]=S.top()+1; S.push(i); } while(S.size()) S.pop(); S.push(V.size()-1); for(int i=V.size()-2;i>=1;i--){ while(S.size()){ if(V[S.top()]>V[i]) break; S.pop(); } if(S.size()==0) R[i]=-1; else R[i]=S.top()-1; S.push(i); } for(int i=1;i<V.size()-1;i++){ if(L[i]==-1) continue; if(R[i]==-1) continue; res.push_back({L[i],R[i]}); } vector<pair<int,int>> r2; if(res.size()){ sort(res.begin(),res.end()); r2.push_back(res[0]); for(int i=1;i<res.size();i++) if(res[i]!=res[i-1]) r2.push_back(res[i]); } return r2; } struct slog{ int duz,kol; } pp; vector<slog> vert[maxn][maxn],hor[maxn][maxn]; ll resi(vector<slog> A,vector<slog> B){ /* cout<<"A JE: "; for(slog x:A) cout<<x.duz<<" "<<x.kol<<" "; cout<<endl; cout<<"B JE: "; for(slog x:B) cout<<x.duz<<" "<<x.kol<<" "; cout<<endl;*/ ll ret=0; for(slog x:A) for(slog y:B){ if(x.duz>y.kol) continue; if(y.duz>x.kol) continue; ret++; } return ret; } ll count_rectangles(std::vector<std::vector<int> > inp) { N=inp.size(); M=inp[0].size(); for(int i=0;i<N;i++) for(int j=0;j<M;j++) mat[i][j]=inp[i][j]; /// Vertikalni for(int i=N-2;i>=1;i--){ vector<int> V; for(int j=0;j<M;j++) V.push_back(mat[i][j]); auto I = getinterval(V); for(auto x:I){ if(mapa[i+1].find(x)!=mapa[i+1].end()) mapa[i][x]=mapa[i+1][x]+1; else mapa[i][x]=1; pp.kol=mapa[i][x]; pp.duz=x.second-x.first+1; vert[i][x.first].push_back(pp); } } /// Horizontalni for(int i=0;i<=M;i++) mapa[i].clear(); for(int i=M-2;i>=1;i--){ vector<int> V; for(int j=0;j<N;j++) V.push_back(mat[j][i]); auto I = getinterval(V); for(auto x:I){ if(mapa[i+1].find(x)!=mapa[i+1].end()) mapa[i][x]=mapa[i+1][x]+1; else mapa[i][x]=1; pp.kol=mapa[i][x]; pp.duz=x.second-x.first+1; hor[x.first][i].push_back(pp); } } ll res=0; for(int i=1;i<=N-2;i++) for(int j=1;j<=M-2;j++){ // cout<<i<<" "<<j<<endl; res+=resi(vert[i][j],hor[i][j]); } return res; }

컴파일 시 표준 에러 (stderr) 메시지

rect.cpp: In function 'std::vector<std::pair<int, int> > getinterval(std::vector<int>)':
rect.cpp:17:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |    for(int i=1;i<V.size();i++){
      |                ~^~~~~~~~~
rect.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    for(int i=1;i<V.size()-1;i++){
      |                ~^~~~~~~~~~~
rect.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |       for(int i=1;i<res.size();i++)
      |                   ~^~~~~~~~~~~
#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...