제출 #266673

#제출 시각아이디문제언어결과실행 시간메모리
266673dennisstarRectangles (IOI19_rect)C++17
10 / 100
2990 ms233956 KiB
#include <bits/stdc++.h> #include "rect.h" #define fi first #define se second #define em emplace #define eb emplace_back using namespace std; using ll = long long; struct dt { int a, b, c; dt() {} dt(int A, int B, int C) : a(A), b(B), c(C) {} bool operator <(const dt &r)const { return tie(a, b, c)<tie(r.a, r.b, r.c); } bool operator ==(const dt &r)const { return tie(a, b, c)==tie(r.a, r.b, r.c); } }; int N, M, A; vector<dt> H, V; ll count_rectangles(vector<vector<int>> a) { N=a.size(); M=a[0].size(); vector<vector<int>> l, r, u, d; for (int i=0; i<N; i++) l.eb(vector<int>(M, -1)); r=u=d=l; for (int i=0; i<N; i++) { vector<int> st; for (int j=0; j<M; j++) { while (st.size()&&a[i][st.back()]<a[i][j]) st.pop_back(); if (st.size()) H.eb(st.back(), j, i); st.eb(j); } st.clear(); for (int j=M-1; j>=0; j--) { while (st.size()&&a[i][st.back()]<a[i][j]) st.pop_back(); if (st.size()) H.eb(j, st.back(), i); st.eb(j); } st.clear(); for (int j=0; j<M; j++) { while (st.size()&&a[i][st.back()]<=a[i][j]) st.pop_back(); if (st.size()) l[i][j]=st.back(); st.eb(j); } st.clear(); for (int j=M-1; j>=0; j--) { while (st.size()&&a[i][st.back()]<=a[i][j]) st.pop_back(); if (st.size()) r[i][j]=st.back(); st.eb(j); } } for (int j=0; j<M; j++) { vector<int> st; for (int i=0; i<N; i++) { while (st.size()&&a[st.back()][j]<a[i][j]) st.pop_back(); if (st.size()) V.eb(st.back(), i, j); st.eb(i); } st.clear(); for (int i=N-1; i>=0; i--) { while (st.size()&&a[st.back()][j]<a[i][j]) st.pop_back(); if (st.size()) V.eb(i, st.back(), j); st.eb(i); } st.clear(); for (int i=0; i<N; i++) { while (st.size()&&a[st.back()][j]<=a[i][j]) st.pop_back(); if (st.size()) u[i][j]=st.back(); st.eb(i); } st.clear(); for (int i=N-1; i>=0; i--) { while (st.size()&&a[st.back()][j]<=a[i][j]) st.pop_back(); if (st.size()) d[i][j]=st.back(); st.eb(i); } } sort(H.begin(), H.end()); H.resize(unique(H.begin(), H.end())-H.begin()); sort(V.begin(), V.end()); V.resize(unique(V.begin(), V.end())-V.begin()); for (int i=1; i<N-1; i++) for (int j=1; j<M-1; j++) { int L=l[i][j], R=r[i][j], U=u[i][j], D=d[i][j]; if (L==-1||R==-1||U==-1||D==-1) continue; dt d1(L, R, U+1), d2(L, R, D-1); int b1=lower_bound(H.begin(), H.end(), d1)-H.begin(); int b2=lower_bound(H.begin(), H.end(), d2)-H.begin(); if (b1>=H.size()||d1<H[b1]) continue; if (b2>=H.size()||d2<H[b2]) continue; if (b2-b1!=D-U-2) continue; d1=dt(U, D, L+1), d2=dt(U, D, R-1); b1=lower_bound(V.begin(), V.end(), d1)-V.begin(); b2=lower_bound(V.begin(), V.end(), d2)-V.begin(); if (b1>=V.size()||d1<V[b1]) continue; if (b2>=V.size()||d2<V[b2]) continue; if (b2-b1!=R-L-2) continue; A++; } return A; }

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

rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:99:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<dt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |   if (b1>=H.size()||d1<H[b1]) continue;
      |       ~~^~~~~~~~~~
rect.cpp:100:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<dt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |   if (b2>=H.size()||d2<H[b2]) continue;
      |       ~~^~~~~~~~~~
rect.cpp:106:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<dt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |   if (b1>=V.size()||d1<V[b1]) continue;
      |       ~~^~~~~~~~~~
rect.cpp:107:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<dt>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   if (b2>=V.size()||d2<V[b2]) continue;
      |       ~~^~~~~~~~~~
#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...