UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213862#2406. Thief Mastersczh12345630825ms12864kbC++111.5kb2024-11-13 22:39:262024-11-13 23:10:47

answer

#include <bits/stdc++.h>
using namespace std;
#define FILE(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout);
int n, m, k, a[1001][1001], ma[1001][1001], mi[1001][1001], ans = 1e9;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= m; i++){
		deque <int> q;
		for (int j = 1; j <= n; j++){
			while (!q.empty() && a[q.back()][i] <= a[j][i]){
				q.pop_back();
			}
			if (!q.empty() && q.front() <= j - k){
				q.pop_front();
			}
			q.push_back(j);
			if (j >= k){
				ma[j][i] = a[q.front()][i];
			}
		}
		while (!q.empty()){
			q.pop_back();
		}
		for (int j = 1; j <= n; j++){
			while (!q.empty() && a[q.back()][i] >= a[j][i]){
				q.pop_back();
			}
			if (!q.empty() && q.front() <= j - k){
				q.pop_front();
			}
			q.push_back(j);
			if (j >= k){
				mi[j][i] = a[q.front()][i];
			}
		}
	}
	for (int i = k; i <= n; i++){
		deque <int> qma, qmi;
		for (int j = 1; j <= m; j++){
			while (!qma.empty() && ma[i][qma.back()] <= a[i][j]){
				qma.pop_back();
			}
			if (!qma.empty() && qma.front() <= j - k){
				qma.pop_front();
			}
			qma.push_back(j);
			while (!qmi.empty() && mi[i][qmi.back()] >= a[i][j]){
				qmi.pop_back();
			}
			if (!qmi.empty() && qmi.front() <= j - k){
				qmi.pop_front();
			}
			qmi.push_back(j);
			if (j >= k){
				ans = min(ans, ma[i][qma.front()] - mi[i][qmi.front()]);
			}
		}
	}
	cout << ans;
	return 0;
}
 

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 222ms
memory: 12236kb

input:

1000 1000 100
804544523 340648618 718292412 235345736 704741136 942776831 741228920 463473302 677289...

output:

865689167

result:

wrong answer 1st lines differ - expected: '998893495', found: '865689167'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1308kb

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: 5ms
memory: 2368kb

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: 164ms
memory: 12864kb

input:

1000 1000 20
1 100001 200001 300001 400001 500001 600001 700001 800001 900001 1000001 1100001 120000...

output:

1901899

result:

ok single line: '1901899'

Test #5:

score: 0
Wrong Answer
time: 32ms
memory: 6748kb

input:

500 500 50
79289095 232165705 955620938 481434262 465576217 112035388 50089892 459799006 181906335 3...

output:

751249981

result:

wrong answer 1st lines differ - expected: '995944328', found: '751249981'

Test #6:

score: 0
Wrong Answer
time: 60ms
memory: 6528kb

input:

500 1000 80
499163842 331022295 940054497 684192083 248823911 842132608 629298697 398526298 98438040...

output:

841491445

result:

wrong answer 1st lines differ - expected: '998299092', found: '841491445'

Test #7:

score: 0
Wrong Answer
time: 112ms
memory: 12392kb

input:

1000 1000 80
102 134 429 251 299 109 264 669 727 296 112 550 270 270 544 660 131 546 968 219 113 678...

output:

824

result:

wrong answer 1st lines differ - expected: '998', found: '824'

Test #8:

score: 0
Wrong Answer
time: 32ms
memory: 6356kb

input:

500 500 100
65532583 920409544 753795976 989349545 818384831 778207112 425141881 853270293 542112588...

output:

884879610

result:

wrong answer 1st lines differ - expected: '999172505', found: '884879610'

Test #9:

score: 0
Wrong Answer
time: 58ms
memory: 6376kb

input:

500 1000 100
456896744 779471086 578349238 52507342 192194992 156396237 475084995 775765435 96617474...

output:

865749347

result:

wrong answer 1st lines differ - expected: '998801667', found: '865749347'

Test #10:

score: 0
Wrong Answer
time: 140ms
memory: 12236kb

input:

1000 1000 100
629053044 957239666 456746076 940194386 201529807 592062148 244394389 825620014 223976...

output:

868449052

result:

wrong answer 1st lines differ - expected: '998862873', found: '868449052'