結果
| 問題 | No.1668 Grayscale |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-10 02:56:13 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 282 ms / 4,000 ms |
| コード長 | 1,208 bytes |
| 記録 | |
| コンパイル時間 | 1,343 ms |
| コンパイル使用メモリ | 219,360 KB |
| 実行使用メモリ | 19,072 KB |
| 最終ジャッジ日時 | 2026-06-20 23:02:18 |
| 合計ジャッジ時間 | 3,688 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:15:11: warning: ignoring return value of '_FIter std::unique(_FIter, _FIter) [with _FIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]', declared with attribute 'nodiscard' [-Wunused-result]
15 | unique(begin(v), end(v));
| ~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:63,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algo.h:875:5: note: declared here
875 | unique(_ForwardIterator __first, _ForwardIterator __last)
| ^~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
int h, w, n, a[1010][1010], dp[1 << 20], nxt[1 << 20];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> h >> w >> n;
for(int i = 0; i < h; i++)
for(int j = 0; j < w; j++) cin >> a[i][j];
vector<int> v;
v.reserve(h * w);
for(int i = 0; i < h; i++)
for(int j = 0; j < w; j++) v.emplace_back(a[i][j]);
sort(begin(v), end(v));
unique(begin(v), end(v));
for(int i = 0; i < h; i++)
for(int j = 0; j < w; j++) a[i][j] = lower_bound(begin(v), begin(v) + n, a[i][j]) - begin(v);
dp[0] = 1;
for(int i = 0; i < n; i++) nxt[i] = n;
for(int i = 0; i < h - 1; i++)
for(int j = 0; j < w; j++) {
auto [x, y] = minmax(a[i][j], a[i + 1][j]);
if(x != y) nxt[x] = min(nxt[x], y);
}
for(int i = 0; i < h; i++)
for(int j = 0; j < w - 1; j++) {
auto [x, y] = minmax(a[i][j], a[i][j + 1]);
if(x != y) nxt[x] = min(nxt[x], y);
}
for(int i = 0; i < n; i++) {
dp[i + 1] = max(dp[i + 1], dp[i]);
if(nxt[i] != n) dp[nxt[i]] = max(dp[nxt[i]], dp[i] + 1);
}
cout << dp[n] << endl;
}