ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#189253 | #3320. 矩形(square) | joy20101 | 100 | 3884ms | 498260kb | C++11 | 3.9kb | 2023-10-04 09:31:59 | 2023-10-04 12:57:52 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#if __cplusplus > 201403L
#define r
#else
#define r register
#endif
#define c const
namespace _c
{
c double pi = acos(-1.0);
namespace min
{
c int i8 = -128;
c int i16 = -32768;
c int i = -2147483647 - 1;
c ll l = -9223372036854775807LL - 1;
} // namespace min
namespace max
{
c int i8 = 127;
c int i16 = 32767;
c int i = 2147483647;
c ll l = 9223372036854775807LL;
} // namespace max
} // namespace _c
namespace _f
{
template <typename T>
inline c T gcd(T m, T n)
{
while (n != 0)
{
T t = m % n;
m = n;
n = t;
}
return m;
}
template <typename T>
inline c T abs(c T &a)
{
return a > 0 ? a : -a;
}
template <typename T>
inline T pow(T a, T b)
{
T res = 1;
while (b > 0)
{
if (b & 1)
{
res = res * a;
}
a = a * a;
b >>= 1;
}
return res;
}
template <typename T>
inline T pow(T a, T b, c T &m)
{
a %= m;
T res = 1;
while (b > 0)
{
if (b & 1)
{
res = res * a % m;
}
a = a * a % m;
b >>= 1;
}
return res % m;
}
} // namespace _f
namespace io
{
template <typename T>
inline T read()
{
r T res = 0, neg = 1;
char g = getchar();
for (; !isdigit(g); g = getchar())
{
if (g == '-')
{
neg = -1;
}
}
for (; isdigit(g); g = getchar())
{
res = res * 10 + g - '0';
}
return res * neg;
}
template <typename T>
inline void read(T &t)
{
t = read<T>();
}
template <typename T>
inline void readln(c T first, c T last)
{
for (r T it = first; it != last; it++)
{
read(*it);
}
}
template <typename T>
inline void _write(T x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9)
{
_write(x / 10);
}
putchar(x % 10 + '0');
}
template <typename T>
inline void write(c T &x, c char &sep = ' ')
{
_write(x);
putchar(sep);
}
template <typename T>
inline void writeln(c T &x)
{
write(x, '\n');
}
template <typename T>
inline void writeln(c T first, c T last, c char &sep = ' ', c char &ends = '\n')
{
for (r T it = first; it != last; it++)
{
write(*it, sep);
}
putchar(ends);
}
#if __cplusplus >= 201103L
template <typename T, typename... Args>
void read(T &x, Args &... args)
{
read(x);
read(args...);
}
#endif
} // namespace io
#undef c
#undef r
int n,m,a[505][505],cnt[505][505][505],l,r,mid,ans[505][505],tmp;
bool check(int x1,int y1,int p){
int x2=x1+p-1,y2=y1+p-1,res=0;
for(int i=1;i<=n;i++)
if(cnt[x2][y2][i]-cnt[x2][y1-1][i]-cnt[x1-1][y2][i]+cnt[x1-1][y1-1][i])
res++;
// cout<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<' '<<p<<' '<<res<<' '<<"boom"<<endl;
return res<=m;
}
int main(){
// freopen("ex_square.in","r",stdin);
// freopen("ex_square.out","w",stdout);
io::read(n),io::read(m);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
io::read(a[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
cnt[i][j][k]=cnt[i-1][j][k]+cnt[i][j-1][k]-cnt[i-1][j-1][k]+(a[i][j]==k);
for(int i=n;i>=1;i--){
for(int j=n;j>=1;j--){
if(i==n||j==n){
ans[i][j]=1;
continue;
}
if(check(i,j,ans[i+1][j+1]+1)){
ans[i][j]=ans[i+1][j+1]+1;
continue;
}
l=1,r=min({n-i+1,n-j+1,ans[i+1][j+1]+1}),tmp=0;
while(l<=r){
mid=l+r>>1;
if(check(i,j,mid))
tmp=mid,l=mid+1;
else
r=mid-1;
}
// printf("%d ",tmp);
ans[i][j]=tmp;
}
// puts("");
}
for(int i=1;i<=n;i++){
for(int j=1;j<n;j++)
io::write(ans[i][j],' ');
io::writeln(ans[i][n]);
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 6380kb
input:
50 12 8 1 9 3 12 10 2 3 5 3 8 6 2 3 11 6 7 3 2 8 10 3 7 11 2 1 10 4 10 5 9 8 5 4 11 5 2 5 11 10 7 5 ...
output:
12 11 10 9 8 7 6 5 4 4 5 5 5 12 12 12 12 12 12 12 12 12 12 12 18 18 17 16 15 14 13 12 11 10 10 10 10...
result:
ok 50 lines
Test #2:
score: 10
Accepted
time: 4ms
memory: 6384kb
input:
50 14 3 13 9 2 14 12 3 13 6 13 7 12 3 10 13 4 12 4 10 9 8 6 1 14 9 13 2 6 1 2 3 13 11 4 2 6 10 5 14 ...
output:
7 7 18 17 16 15 14 13 12 11 10 9 8 7 7 7 7 6 5 6 5 18 17 16 15 14 13 12 12 12 12 12 12 12 12 12 12 1...
result:
ok 50 lines
Test #3:
score: 10
Accepted
time: 0ms
memory: 6380kb
input:
50 17 17 8 14 12 2 7 17 3 11 5 8 15 11 4 3 15 13 12 6 5 9 3 9 8 7 13 3 7 7 13 16 6 10 17 16 7 6 5 3 ...
output:
19 19 19 19 19 19 19 18 17 16 15 14 13 12 11 10 9 8 7 6 6 6 8 8 8 7 12 12 12 11 10 9 8 7 6 7 9 9 9 8...
result:
ok 50 lines
Test #4:
score: 10
Accepted
time: 481ms
memory: 498256kb
input:
500 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 3 3 3 29 29 29 29 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15...
result:
ok 500 lines
Test #5:
score: 10
Accepted
time: 429ms
memory: 498256kb
input:
500 2 2 1 1 1 1 1 1 2 1 2 1 1 2 2 1 2 2 2 1 1 2 1 2 1 1 2 1 2 2 2 2 1 1 2 2 2 2 1 2 2 1 2 1 1 1 1 2 ...
output:
500 499 498 497 496 495 494 493 492 491 490 489 488 487 486 485 484 483 482 481 480 479 478 477 476 ...
result:
ok 500 lines
Test #6:
score: 10
Accepted
time: 501ms
memory: 498260kb
input:
500 2 2 1 2 1 1 1 1 2 1 1 1 1 1 2 2 1 1 1 2 2 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 2 2 2 1 1 1 2 1 2 1 1 2 ...
output:
13 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 47 47 47 47 47 47 47 47 47 46 45 44 43 42 41 4...
result:
ok 500 lines
Test #7:
score: 10
Accepted
time: 488ms
memory: 498260kb
input:
500 2 1 1 2 2 2 1 2 1 2 2 1 2 1 2 2 2 2 1 1 1 1 1 1 2 1 1 1 1 1 2 2 1 2 2 2 2 1 1 2 1 2 2 1 2 2 2 2 ...
output:
49 49 49 49 49 49 49 49 49 49 49 49 49 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 2...
result:
ok 500 lines
Test #8:
score: 10
Accepted
time: 728ms
memory: 498256kb
input:
500 162 11 100 62 113 44 157 79 78 156 9 78 50 149 145 54 72 138 145 5 55 51 129 37 114 95 3 63 5 21...
output:
29 29 29 28 28 27 26 28 28 29 29 29 29 29 29 28 27 26 25 24 24 24 25 26 26 25 25 25 27 26 25 25 29 2...
result:
ok 500 lines
Test #9:
score: 10
Accepted
time: 642ms
memory: 498256kb
input:
500 171 23 35 15 28 60 69 4 90 37 165 8 163 129 20 87 61 115 39 135 78 55 96 21 118 165 23 145 21 16...
output:
30 29 28 27 27 31 30 29 28 27 27 27 27 28 27 26 28 29 28 27 29 30 29 28 27 30 29 33 32 31 30 29 28 3...
result:
ok 500 lines
Test #10:
score: 10
Accepted
time: 611ms
memory: 498260kb
input:
500 168 141 99 128 16 72 106 42 137 15 57 113 3 17 116 13 91 147 104 55 125 32 46 85 51 103 15 156 7...
output:
28 28 28 28 31 31 31 31 31 30 29 28 27 27 27 27 29 29 29 29 29 30 29 29 29 29 29 29 29 29 29 29 28 2...
result:
ok 500 lines
Extra Test:
score: 0
Extra Test Passed