結果

問題 No.1668 Grayscale
コンテスト
ユーザー noimi
提出日時 2021-06-10 02:56:40
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,178 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,363 ms
コンパイル使用メモリ 216,420 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2026-06-20 23:02:37
合計ジャッジ時間 4,044 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other AC * 15 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:13:11: warning: ignoring return value of '_FIter std::unique(_FIter, _FIter) [with _FIter = int*]', declared with attribute 'nodiscard' [-Wunused-result]
   13 |     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)
      |     ^~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int h, w, n, a[1010][1010], dp[1 << 20], nxt[1 << 20], v[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];
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++) v[i * w + j] = 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;
}
0