제출 #249444

#제출 시각아이디문제언어결과실행 시간메모리
249444LittleFlowers__Rectangles (IOI19_rect)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;}) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l,int r){return l+rng()%(r-l+1);} #define fasty ios_base::sync_with_stdio(0),cin.tie(0); #define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a) #define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a) #define forv(a,b) for(auto&a:b) #define fi first #define se second #define pb push_back #define ii pair<int,int> #define mt make_tuple #define all(a) a.begin(),a.end() #define reset(f, x) memset(f, x, sizeof(f)) #define gg exit(0); const int N=2510; int m,n; int a[N][N]; int rt[N][N], lf[N][N], dw[N][N], up[N][N]; int to_dw[N][N], to_up[N][N]; int top; int w[N]; int cnt,x1,x2,y1,y2; int dd[N][N]; void dfs(int i,int j){ if(1>i||i>m||1>j||j>n||dd[i][j]||a[i][j]) return; dd[i][j]=1; cnt++; x1=min(x1,i), x2=max(x2,i), y1=min(y1,j), y2=max(y2,j); dfs(i-1,j); dfs(i,j-1); dfs(i+1,j); dfs(i,j+1); } long long count_rectangles(vector<vector<int>> arr){ m=arr.size(), n=arr[0].size(); int mx=0; forinc(i,1,m) forinc(j,1,n) mx=max(mx,a[i][j]=arr[i-1][j-1]); if(mx<=1){ int tot=0; forinc(i,2,m-1){ forinc(j,2,n-1) if(dd[i][j] + a[i][j] == 0){ x1=x2=i, y1=y2=j; dfs(i,j); if(cnt==(x2-x1+1)*(y2-y1+1) && 1<x1&&x2<m && 1<y1&&y2<n) tot++; } } return tot; } forinc(i,1,m){ top=0; fordec(j,n,1){ while(top && a[i][j]>a[i][w[top]]) top--; rt[i][j]=top ? w[top] : 0; while(top && a[i][j]==a[i][w[top]]) top--; w[++top]=j; } top=0; forinc(j,1,n){ while(top && a[i][j]>a[i][w[top]]) top--; lf[i][j]=top ? w[top] : 0; while(top && a[i][j]==a[i][w[top]]) top--; w[++top]=j; } } forinc(j,1,n){ top=0; fordec(i,m,1){ while(top && a[i][j]>a[w[top]][j]) top--; dw[i][j]=top ? w[top] : 0; while(top && a[i][j]==a[w[top]][j]) top--; w[++top]=i; } top=0; forinc(i,1,m){ while(top && a[i][j]>a[w[top]][j]) top--; up[i][j]=top ? w[top] : 0; while(top && a[i][j]==a[w[top]][j]) top--; w[++top]=i; } } auto chk=[&](int x,int y,int u,int v){ if(y-x<2) return 0; int suc=1; forinc(i,x+1,y-1) if(rt[i][u-1]!=v+1 && lf[i][v+1]!=u-1) return 0; return 1; }; if(m==3){ int tot=0; forinc(i,2,n-1) if(a[2][i]<a[1][i] && a[2][i]<a[3][i]){ int j=i; while(j<n && a[2][j]<a[1][j] && a[2][j]<a[3][j]){ tot+=rt[2][i-1]==j+1 || lf[2][j+1]==i-1; j++; } } return tot; } else{ int tot=0; forinc(i,1,m){ forinc(j,2,n-1){ if(!to_up[i][j] && up[i][j]){ int t=up[i][j]; int k=j; int bp=0; while(k<n && (up[i][k]==t || dw[t][k]==i)){ if(to_up[i][k] && up[i][k]==t || to_dw[t][k] && dw[t][k]==i){ bp=k; k=to_up[i][k] && up[i][k]==t ? to_up[i][k] : to_dw[t][k]; break; } k++; } if(!bp) bp=k; forinc(l,j,bp-1){ if(up[i][l]==t) to_up[i][l]=k; if(dw[t][l]==i) to_dw[t][l]=k; } forinc(l,j,bp-1) forinc(r,l,k-1) tot+=chk(t,i,l,r); } if(!to_dw[i][j] && dw[i][j]){ int t=dw[i][j]; int k=j; int bp=0; while(k<n && (up[t][k]==i || dw[i][k]==t)){ if(to_up[t][k] && up[t][k]==i || to_dw[i][k] && dw[i][k]==t){ bp=k; k=to_up[t][k] && up[t][k]==i ? to_up[t][k] : to_dw[i][k]; break; } k++; } if(!bp) bp=k; forinc(l,j,bp-1){ if(up[t][l]==i) to_up[t][l]=k; if(dw[i][l]==t) to_dw[i][l]=k; } forinc(l,j,bp-1) forinc(r,l,k-1) tot+=chk(i,t,l,r); } } } return tot; } } #ifdef UNX main(){ #define task "TASK" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } int m,n; m=in,n=in; vector<vector<int>> a(m,vector<int>(n)); forv(i,a) forv(j,i) j=in; cout<<count_rectangles(a)<<"\n"; } #endif // UNX

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

rect.cpp:29:15: error: 'int y1' redeclared as different kind of symbol
 int cnt,x1,x2,y1,y2;
               ^~
In file included from /usr/include/features.h:367:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from rect.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:251:1: note: previous declaration 'double y1(double)'
 __MATHCALL (y1,, (_Mdouble_));
 ^
rect.cpp: In function 'void dfs(int, int)':
rect.cpp:36:44: error: no matching function for call to 'min(double (&)(double) noexcept, int&)'
     x1=min(x1,i), x2=max(x2,i), y1=min(y1,j), y2=max(y2,j);
                                            ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from rect.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
rect.cpp:36:44: note:   deduced conflicting types for parameter 'const _Tp' ('double(double) noexcept' and 'int')
     x1=min(x1,i), x2=max(x2,i), y1=min(y1,j), y2=max(y2,j);
                                            ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from rect.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
rect.cpp:36:44: note:   deduced conflicting types for parameter 'const _Tp' ('double(double) noexcept' and 'int')
     x1=min(x1,i), x2=max(x2,i), y1=min(y1,j), y2=max(y2,j);
                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from rect.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
rect.cpp:36:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'double (*)(double) noexcept'
     x1=min(x1,i), x2=max(x2,i), y1=min(y1,j), y2=max(y2,j);
                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from rect.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
rect.cpp:36:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'double (*)(double) noexcept'
     x1=min(x1,i), x2=max(x2,i), y1=min(y1,j), y2=max(y2,j);
                                            ^
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:53:32: error: assignment of function 'double y1(double)'
                 x1=x2=i, y1=y2=j;
                                ^
rect.cpp:53:32: error: cannot convert 'int' to 'double(double) noexcept' in assignment
rect.cpp:55:38: error: invalid operands of types 'int' and 'double(double) noexcept' to binary 'operator-'
                 if(cnt==(x2-x1+1)*(y2-y1+1) && 1<x1&&x2<m && 1<y1&&y2<n)
                                    ~~^~~
rect.cpp:55:64: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
                 if(cnt==(x2-x1+1)*(y2-y1+1) && 1<x1&&x2<m && 1<y1&&y2<n)
                                                                ^~
rect.cpp: In lambda function:
rect.cpp:98:13: warning: unused variable 'suc' [-Wunused-variable]
         int suc=1;
             ^~~
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:121:40: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
                         if(to_up[i][k] && up[i][k]==t || to_dw[t][k] && dw[t][k]==i){
                            ~~~~~~~~~~~~^~~~~~~~~~~~~~
rect.cpp:140:40: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
                         if(to_up[t][k] && up[t][k]==i || to_dw[i][k] && dw[i][k]==t){
                            ~~~~~~~~~~~~^~~~~~~~~~~~~~