이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double cur = rngesus(0, MASK(60) - 1);
cur /= MASK(60) - 1;
return l + cur * (r - l);
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
int n, m;
namespace Sub1{
ll solve(vector<vector<int>> a){
ll ans = 0;
short row_pref[n][n][m], col_pref[m][m][n];
memset(row_pref, 0, sizeof row_pref);
memset(col_pref, 0, sizeof col_pref);
for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j){
int ma = 0;
for(int k = i + 1; k + 1 < n; ++k){
maximize(ma, a[k][j]);
if (ma >= a[i][j]) break;
if (ma < a[k+1][j]){
row_pref[i][k+1][j] = 1;
}
}
ma = 0;
for(int k = j + 1; k + 1 < m; ++k){
maximize(ma, a[i][k]);
if (ma >= a[i][j]) break;
if (ma < a[i][k+1]){
col_pref[j][k+1][i] = 1;
}
}
}
for(int i = 0; i<n; ++i) for(int j = i + 2; j < n; ++j) for(int k = 1; k < m; ++k) row_pref[i][j][k] += row_pref[i][j][k-1];
for(int i = 0; i<m; ++i) for(int j = i + 2; j < m; ++j) for(int k = 1; k < n; ++k) col_pref[i][j][k] += col_pref[i][j][k-1];
for(int i = 0; i<n; ++i) for(int x = i + 2; x < n; ++x)
for(int j = 0; j<m; ++j) for(int y = j + 2; y < m; ++y){
int cnt1 = row_pref[i][x][y-1] - row_pref[i][x][j];
int cnt2 = col_pref[j][y][x-1] - col_pref[j][y][i];
if (cnt1 == y - j - 1 && cnt2 == x - i - 1) ans++;
}
return ans;
}
}
namespace Sub6{
bool check(vector<vector<int>> a){
for(int i= 0; i<n; ++i) for(int j = 0; j<m; ++j) if (a[i][j] > 1) return false;
return true;
}
ll solve(vector<vector<int>> a){
ll ans = 0;
vector<int> cnt0(m), cnt1(m);
for(int i = 2; i<n; ++i){
for(int j = 0; j < m; ++j){
if (a[i-1][j] == 0){
cnt0[j]++;
cnt1[j] = 0;
}
else{
cnt0[j] = 0;
cnt1[j]++;
}
}
vector<int> pillar; pillar.reserve(m);
for(int j = 0; j < m; ++j) if (cnt1[j]) pillar.push_back(j);
for(int j = 1; j < pillar.size(); ++j){
int l = pillar[j-1], r = pillar[j];
if (l == r + 1) continue;
bool check = true;
for(int k = l + 1; k < r; ++k) if (!a[i][k]) check = false;
for(int k = l + 2; k < r; ++k) if (cnt0[k] != cnt0[k-1]) check = false;
if (check && cnt0[l+1] <= min(cnt1[l], cnt1[r]))
ans++;
}
}
return ans;
}
}
ll count_rectangles(vector<vector<int>> a) {
n = a.size(), m = a[0].size();
if (Sub6::check(a)) return Sub6::solve(a);
return Sub1::solve(a);
}
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'll Sub6::solve(std::vector<std::vector<int> >)':
rect.cpp:125:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | for(int j = 1; j < pillar.size(); ++j){
| ~~^~~~~~~~~~~~~~~
# | 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... |