結果

問題 No.3829 今日は何人に会えるかな?
コンテスト
ユーザー otoshigo
提出日時 2026-11-29 13:59:31
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 199 ms / 2,000 ms
+ 288µs
コード長 1,814 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,764 ms
コンパイル使用メモリ 353,044 KB
実行使用メモリ 46,336 KB
最終ジャッジ日時 2026-11-29 13:59:40
合計ジャッジ時間 7,859 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define rep(i, s, t) for (ll i = (ll)s; i < (ll)(t); i++)
#define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

template <class T1, class T2>
bool chmin(T1& x, T2 y) { return x > y ? (x = y, true) : false; }
template <class T1, class T2>
bool chmax(T1& x, T2 y) { return x < y ? (x = y, true) : false; }

template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using max_heap = priority_queue<T>;

const int MAX = 1000;

void solve() {
    int N, H, W;
    cin >> N >> H >> W;
    vector<string> S(H);
    rep(i, 0, H) cin >> S[i];
    int x, y;
    cin >> x >> y;
    x--, y--;
    vector fr(MAX + 1, vector(H, vector<int>(W)));
    rep(i, 0, N) {
        int r, c, t;
        cin >> r >> c >> t;
        r--, c--;
        fr[t][r][c]++;
    }
    vector dp(MAX + 1, vector(H, vector<int>(W, -inf)));
    dp[0][x][y] = 0;
    rep(t, 1, MAX + 1) {
        rep(i, 0, H) rep(j, 0, W) {
            rep(k, 0, 5) {
                int ex, ey;
                if (k < 4) ex = i + dx[k], ey = j + dy[k];
                else ex = i, ey = j;
                if (0 <= ex && ex < H && 0 <= ey && ey < W && S[ex][ey] != '#') {
                    chmax(dp[t][ex][ey], dp[t - 1][i][j] + fr[t][ex][ey]);
                }
            }
        }
    }
    int ans = 0;
    rep(i, 0, H) rep(j, 0, W) chmax(ans, dp[MAX][i][j]);
    cout << ans << "\n";
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cout << fixed << setprecision(15);
    srand(time(NULL));

    int T;
    // cin >> T;
    T = 1;
    while (T--) solve();
}
0