QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#776861#9788. Shrecklessucup-team3670#WA 21ms3816kbC++201.2kb2024-11-23 21:20:252024-11-23 21:20:26

Judging History

你现在查看的是最新测评结果

  • [2024-11-23 21:20:26]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:3816kb
  • [2024-11-23 21:20:25]
  • 提交

answer

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define sz(a) (int)((a).size())

using namespace std;

typedef long long li;

void solve(){
	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(n, vector<int>(m));
	forn(i, n) forn(j, m) cin >> a[i][j];
	vector<pair<int, int>> ord(n * m);
	forn(i, n) forn(j, m) ord[i * m + j] = {i, j};
	sort(ord.begin(), ord.end(), [&](const pair<int, int> &x, const pair<int, int> &y){
		if (a[x.first][x.second] != a[y.first][y.second])
			return a[x.first][x.second] > a[y.first][y.second];
		return x.second < y.second;
	});
	multiset<int> cur;
	int cnt = 0;
	forn(i, n * m){
		int j = i - 1;
		vector<int> add;
		while (j + 1 < n * m && a[ord[j + 1].first][ord[j + 1].second] == a[ord[i].first][ord[i].second]){
			++j;
			if (!cur.empty() && *cur.begin() < ord[j].second){
				cur.erase(prev(cur.lower_bound(ord[j].second)));
				++cnt;
			}
			else{
				add.push_back(ord[j].second);
			}
		}
		for (int x : add){
			cur.insert(x);
		}
		i = j;
	}
	cout << (cnt >= n ? "YES" : "NO") << '\n';
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

3
2 2
69 69
2024 42
3 3
1 1 1
1 1 1
2 2 2
3 4
1 1 1 1
1 1 1 1
2 2 2 2

output:

YES
NO
YES

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

3
2 2
69 69
2024 42
3 3
1 1 1
1 1 1
2 2 2
3 4
1 1 1 1
1 1 1 1
2 2 2 2

output:

YES
NO
YES

result:

ok 3 token(s): yes count is 2, no count is 1

Test #3:

score: -100
Wrong Answer
time: 21ms
memory: 3616kb

input:

20000
6 2
12 4
8 24
2 10
1 22
3 15
18 20
3 3
3 8 18
2 17 15
13 4 6
3 3
7 17 15
8 6 3
18 13 9
3 3
2 3 14
1 7 17
4 6 13
3 3
6 10 14
3 9 13
1 7 15
2 4
1 3 16 14
6 10 4 2
3 3
3 2 17
7 11 13
16 5 18
2 3
2 3 6
4 1 5
2 4
4 6 13 14
2 11 12 16
3 3
2 8 12
4 9 17
5 7 18
3 2
5 10
8 9
1 6
2 2
2 4
1 3
2 3
12 6 1
...

output:

NO
NO
YES
NO
NO
YES
YES
YES
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
YES
NO
NO
NO
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
NO
NO
YES
NO
YES
YES
NO
NO
YES
NO
YES
NO
NO
YES
YES
YES
NO
NO
NO
YES
YES
YES
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
NO...

result:

wrong answer expected YES, found NO [2nd token]