优先队列的为什么过不了QAQ

P1434 [SHOI2002] 滑雪

@[heiheiwolala](/user/765192) 应该由海拔从低到高枚举 ```cpp struct Compare { bool operator()(const Item &a, const Item &b) { return a.val < b.val; } }; void solve() { int n, m; cin >> n >> m; memset(maxHigh, 0, sizeof(maxHigh)); memset(Height, 0, sizeof(Height)); priority_queue<Item, vector<Item>, Compare> pq; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> Height[i][j]; pq.push(Item(Height[i][j], i, j)); } } int res = 0; while (!pq.empty()) { Item item = pq.top(); int val = item.val, i = item.indices.first, j = item.indices.second; if (val < Height[i - 1][j]) maxHigh[i][j] = max(maxHigh[i][j], maxHigh[i - 1][j] + 1); if (val < Height[i][j + 1]) maxHigh[i][j] = max(maxHigh[i][j], maxHigh[i][j + 1] + 1); if (val < Height[i + 1][j]) maxHigh[i][j] = max(maxHigh[i][j], maxHigh[i + 1][j] + 1); if (val < Height[i][j - 1]) maxHigh[i][j] = max(maxHigh[i][j], maxHigh[i][j - 1] + 1); res = max(res, maxHigh[i][j]); pq.pop(); //cout << res << "(" << i << "," << j << ") " << val << endl; } cout << res+1 << "\n"; return; } ``` 这样就能[过了](https://www.luogu.com.cn/record/141847510) OAO
by KinoTsuki @ 2024-01-03 22:32:28


|