이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
int n,m;
Vi vr[2500][2500],vc[2500][2500];
int L[2500][2500],R[2500][2500],U[2500][2500],D[2500][2500];
ll count_rectangles(vector<Vi> a){
MEM_1(L);MEM_1(R);MEM_1(U);MEM_1(D);
n=a.size(),m=a[0].size();
fup(i,1,n-2,1){
stack<Pi> st;
fup(j,0,m-1,1){
while(!st.empty() && st.top().X<=a[i][j])st.pop();
if(!st.empty())L[i][j]=st.top().Y;
st.push(mp(a[i][j],j));
}
while(!st.empty())st.pop();
fdn(j,m-1,0,1){
while(!st.empty() && st.top().X<=a[i][j])st.pop();
if(!st.empty())R[i][j]=st.top().Y;
st.push(mp(a[i][j],j));
}
fup(j,1,m-2,1){
if(L[i][j]!=-1 && R[i][j]!=-1)vc[L[i][j]+1][R[i][j]-1].pb(i);
}
}
fup(j,1,m-2,1){
stack<Pi> st;
fup(i,0,n-1,1){
while(!st.empty() && st.top().X<=a[i][j])st.pop();
if(!st.empty())U[i][j]=st.top().Y;
st.push(mp(a[i][j],i));
}
while(!st.empty())st.pop();
fdn(i,n-1,0,1){
while(!st.empty() && st.top().X<=a[i][j])st.pop();
if(!st.empty())D[i][j]=st.top().Y;
st.push(mp(a[i][j],i));
}
fup(i,1,n-2,1){
if(U[i][j]!=-1 && D[i][j]!=-1)vr[U[i][j]+1][D[i][j]-1].pb(j);
}
}
fup(i,1,n-2,1)fup(j,1,m-2,1){
sort(ALL(vr[i][j]));vr[i][j].resize(unique(ALL(vr[i][j]))-vr[i][j].begin());
sort(ALL(vc[i][j]));vc[i][j].resize(unique(ALL(vc[i][j]))-vc[i][j].begin());
}
vector<iiii> vv;
fup(i,1,n-2,1){
fup(j,1,m-2,1){
if(L[i][j]!=-1 && R[i][j]!=-1 && U[i][j]!=-1 && D[i][j]!=-1)vv.emplace_back(L[i][j]+1,R[i][j]-1,U[i][j]+1,D[i][j]-1);
}
}
ll ans=0;
sort(ALL(vv));vv.resize(unique(ALL(vv))-vv.begin());
for(auto &I:vv){
auto [y1,y2,x1,x2]=I;
if(vr[x1][x2].empty() || vc[y1][y2].empty())continue;
int t1=lower_bound(ALL(vr[x1][x2]),y1)-vr[x1][x2].begin(),t2=t1+y2-y1;
int N=vr[x1][x2].size();
if(t1==N || t2>=N || vr[x1][x2][t1]!=y1 || vr[x1][x2][t2]!=y2)continue;
t1=lower_bound(ALL(vc[y1][y2]),x1)-vc[y1][y2].begin(),t2=t1+x2-x1;
N=vc[y1][y2].size();
if(t1==N || t2>=N || vc[y1][y2][t1]!=x1 || vc[y1][y2][t2]!=x2)continue;
ans++;
}
return ans;
}/*
int main() {
int n,m;
scanf("%d%d",&n,&m);
vector<Vi> v(n,Vi(m));
fup(i,0,n-1,1)fup(j,0,m-1,1)scanf("%d",&v[i][j]);
printf("%lld\n",count_rectangles(v));
}*/
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:50:2: note: in expansion of macro 'fup'
50 | fup(i,1,n-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:52:3: note: in expansion of macro 'fup'
52 | fup(j,0,m-1,1){
| ^~~
rect.cpp:11:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
| ^
rect.cpp:58:3: note: in expansion of macro 'fdn'
58 | fdn(j,m-1,0,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:63:3: note: in expansion of macro 'fup'
63 | fup(j,1,m-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:67:2: note: in expansion of macro 'fup'
67 | fup(j,1,m-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:69:3: note: in expansion of macro 'fup'
69 | fup(i,0,n-1,1){
| ^~~
rect.cpp:11:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
| ^
rect.cpp:75:3: note: in expansion of macro 'fdn'
75 | fdn(i,n-1,0,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:80:3: note: in expansion of macro 'fup'
80 | fup(i,1,n-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:84:2: note: in expansion of macro 'fup'
84 | fup(i,1,n-2,1)fup(j,1,m-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:84:16: note: in expansion of macro 'fup'
84 | fup(i,1,n-2,1)fup(j,1,m-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:89:2: note: in expansion of macro 'fup'
89 | fup(i,1,n-2,1){
| ^~~
rect.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
rect.cpp:90:3: note: in expansion of macro 'fup'
90 | fup(j,1,m-2,1){
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |