結果

問題 No.1668 Grayscale
ユーザー sapphire__15sapphire__15
提出日時 2021-09-04 13:50:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,267 ms / 4,000 ms
コード長 2,438 bytes
コンパイル時間 1,775 ms
コンパイル使用メモリ 141,188 KB
実行使用メモリ 87,184 KB
最終ジャッジ日時 2023-08-22 21:23:29
合計ジャッジ時間 7,041 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 499 ms
81,232 KB
testcase_07 AC 504 ms
81,124 KB
testcase_08 AC 149 ms
7,304 KB
testcase_09 AC 1,267 ms
87,184 KB
testcase_10 AC 361 ms
34,156 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 3 ms
4,572 KB
testcase_13 AC 37 ms
8,008 KB
testcase_14 AC 151 ms
18,236 KB
testcase_15 AC 71 ms
9,920 KB
testcase_16 AC 47 ms
7,232 KB
testcase_17 AC 25 ms
6,336 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,508 KB
testcase_21 AC 3 ms
4,384 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>
#include <iomanip>
#include <limits>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <cstring>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;

#define rip(_i, _n, _s) for (int _i = (_s); _i < (int)(_n); _i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename _T>
using MaxHeap = std::priority_queue<_T>;
template<typename _T>
using MinHeap = std::priority_queue<_T, std::vector<_T>, std::greater<_T>>;

template<typename _T>
inline bool chmax(_T &_l, const _T _b) {
    if (_b > _l) {
        _l = _b;
        return true;
    }
    return false;
}
template<typename _T>
inline bool chmin(_T &_l, const _T _b) {
    if (_l > _b) {
        _l = _b;
        return true;
    }
    return false;
}

template<typename _T>
void vdeb(const std::vector<_T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename _T>
void vdeb(const std::vector<std::vector<_T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ": ";
        vdeb(bb[i]);
    }
    std::cout << '\n';
}

using namespace std;

int dx[] = {0, 1, 0, -1, 0};

int main() {
    int h, w, n; cin >> h >> w >> n;
    vector<vector<int>> da(h, vector<int>(w));
    rip(i,h,0) rip(j, w,0) cin >> da[i][j];

    auto in_grid = [h, w](int x, int y) {
        return 0 <= x && x < h && 0 <= y && y < w;
    };
    vector<vector<pair<int, bool>>> ed(n, vector<pair<int, bool>>(0));
    rip(i,n,1) {
        ed[i-1].push_back({i, false});
    }
    rip(i,h,0) rip(j,w,0) {
        rip(k,4,0) {
            int nx = i + dx[k], ny = j + dx[k+1];
            if(in_grid(nx, ny) && da[i][j] < da[nx][ny]) ed[da[i][j]-1].push_back({da[nx][ny]-1, true});
        }
    }
    vector<int> dp(n, 1);
    rip(i,n-1,0) {
        for(auto &j : ed[i]) {
            if(j.second) chmax(dp[j.first], dp[i]+1);
            else chmax(dp[j.first], dp[i]);
        }
    }

    cout << dp.back() << endl;
}
0