ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#211084 | #3801. Thief Masters | mygr | 100 | 21467ms | 490556kb | C++11 | 4.7kb | 2024-08-09 10:45:22 | 2024-08-09 12:44:15 |
answer
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
typedef long long ll;
#ifdef ONLINE_JUDGE
#define getchar getchar_unlocked
#endif
namespace FastIO
{
char write_cache[40];
template <class T>
inline const T read() noexcept
{
T x(0);
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
f ^= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
template <class T>
inline const void read(T &x) noexcept
{
x = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
f ^= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
x = f ? -x : x;
}
template <class T, class... P>
inline const void read(T &x, P &...ark) noexcept
{
x = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
f ^= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
x = f ? -x : x;
read(ark...);
}
template <class T>
inline const void readu(T &x) noexcept
{
x = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}
template <class T>
inline const T readu() noexcept
{
T x(0);
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return x;
}
template <class T, class... P>
inline const void readu(T &x, P &...ark) noexcept
{
x = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
readu(ark...);
}
template <class T>
inline const void readArr(T *begin, T *end) noexcept
{
while (begin < end)
{
*begin = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
f ^= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
*begin = (*begin << 1) + (*begin << 3) + (ch ^ 48), ch = getchar();
*begin = f ? -*begin : *begin;
}
}
template <class T>
inline const void readArr(T *begin, int cnt) noexcept
{
while (cnt--)
{
read(*begin);
++begin;
}
}
template <class T>
inline const void write(T x) noexcept
{
if (x < 0)
putchar('-'), x = -x;
int cnt = 0;
while (x)
write_cache[cnt++] = x % 10 ^ 48, x /= 10;
if (!cnt)
putchar('0');
else
while (cnt--)
putchar(write_cache[cnt]);
}
template <char end = ' ', class T, class... ARK>
inline const void write(T &x, ARK &...ark) noexcept
{
write(x);
putchar(end);
write(ark...);
}
template <char end = '\n', class T>
inline const void println(T x) noexcept
{
if (x < 0)
putchar('-'), x = -x;
int cnt = 0;
while (x)
write_cache[cnt++] = x % 10 ^ 48, x /= 10;
if (!cnt)
putchar('0');
else
while (cnt--)
putchar(write_cache[cnt]);
putchar(end);
}
template <char sep = ' ', char endl = '\n', class T>
inline const void writeArr(T *begin, T *end) noexcept
{
while (begin < end)
write(*begin), putchar(sep), ++begin;
putchar(endl);
}
template <char sep = ' ', char end = '\n', class T>
inline const void writeArr(T *arr, int cnt)
{
while (cnt--)
{
write(*arr);
putchar(sep);
++arr;
}
putchar(end);
}
}
const int Max=5005;
int A,B,N;
struct Stack{
pii p[Max];
int last,head,type,np;
void add(int num)
{
np++;
while(np-p[last].second>=N)
last++;
while(last<=head and p[head].first<num*type)
head--;
p[++head]=make_pair(num*type,np);
}
int qt()
{
return p[last].first;
}
void clear()
{
head=0;last=1;
np=0;
}
};
Stack s[Max][2],in[2];
int p[Max][Max],Mx[Max][Max];
int read()
{
char c=getchar();
int w=0;
while(!isdigit(c))
c=getchar();
while(isdigit(c))
{
w=w*10+c-'0';
c=getchar();
}
return w;
}
int ans=0x7fffffff;
signed main()
{
FastIO::read(A,B,N);
for(int i=1;i<=A;i++)
{
for(int j=1;j<=B;j++)
{
FastIO::read(p[i][j]);
}
}
for(int i=1;i<=A;i++)
{
s[i][0].type=-1;
s[i][1].type=1;
s[i][0].clear();
s[i][1].clear();
}
in[0].clear();
in[1].clear();
in[0].type=-1;
in[1].type=1;
for(int i=1;i<=B;i++)
{
for(int j=1;j<=A;j++)
{
s[j][0].add(p[j][i]);
s[j][1].add(p[j][i]);
in[0].add(-s[j][0].qt());
in[1].add(s[j][1].qt());
if(i>=N and j>=N)
ans=min(ans,in[1].qt()+in[0].qt());
}
in[0].clear();in[1].clear();
}
printf("%d",ans);
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 3723ms
memory: 490556kb
input:
5000 5000 1000 112860841 963292630 950228017 843100821 628111020 568250408 901169419 322571542 98853...
output:
999988492
result:
ok single line: '999988492'
Test #2:
score: 10
Accepted
time: 43ms
memory: 392812kb
input:
5 4 2 1 2 5 6 0 17 16 0 16 17 0 1 2 10 2 1 1 2 3 2
output:
2
result:
ok single line: '2'
Test #3:
score: 10
Accepted
time: 72ms
memory: 393232kb
input:
100 100 10 2 100001 200001 300001 400001 500001 600001 700001 800001 900001 1000001 1100001 1200001 ...
output:
908999
result:
ok single line: '908999'
Test #4:
score: 10
Accepted
time: 3541ms
memory: 490552kb
input:
5000 5000 1000 8974 8293 3530 8179 6181 2983 6500 3525 2603 1983 6720 5938 9247 2494 4568 9909 3852 ...
output:
9999
result:
ok single line: '9999'
Test #5:
score: 20
Accepted
time: 3244ms
memory: 490556kb
input:
5000 5000 1000 3206 5640 1070 5846 5931 3274 6116 1741 543 6399 1626 115 92 3037 464 100 3700 2694 5...
output:
9999
result:
ok single line: '9999'
Test #6:
score: 10
Accepted
time: 3568ms
memory: 490556kb
input:
5000 5000 1000 9041 1397 3723 7115 4298 5210 8033 5608 6711 6539 7140 5331 4282 2599 59 9363 5817 25...
output:
9999
result:
ok single line: '9999'
Test #7:
score: 10
Accepted
time: 3643ms
memory: 490552kb
input:
5000 5000 1000 19636 14616 3910 15971 9484 16390 2221 13667 5771 1364 2375 15202 16870 7107 13189 16...
output:
21813
result:
ok single line: '21813'
Test #8:
score: 20
Accepted
time: 3633ms
memory: 490552kb
input:
5000 5000 1000 3628 1018 3668 18160 14975 18599 9087 10641 19468 16400 19072 16984 6583 7925 19853 1...
output:
21811
result:
ok single line: '21811'
Extra Test:
score: 0
Extra Test Passed