結果

問題 No.5024 魔法少女うなと宝集め
コンテスト
ユーザー Sqrt10
提出日時 2026-05-02 17:30:07
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,740 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,192 ms
コンパイル使用メモリ 342,064 KB
実行使用メモリ 6,400 KB
スコア 0
最終ジャッジ日時 2026-05-02 17:30:18
合計ジャッジ時間 6,018 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int a[21][21] = {};
int s[22][22] = {};

int sum(int x1, int y1, int x2, int y2) { return s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1]; }

int main() {
        int n, t;
        cin >> n >> t;
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                        cin >> a[i][j];
                }
        }

        for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                        s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + a[i][j];
                }
        }

        double c[21][21] = {};
        const double alpha = .8;
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                        c[i][j] = 0;
                        for (int x = 0; x < n; x++) {
                                for (int y = 0; y < n; y++) {
                                        int d = abs(i - x) + abs(j - y);
                                        c[i][j] += a[x][y] * pow(alpha, d);
                                }
                        }
                }
        }
        // (1) Find the cell with the largest c
        int si = 0, sj = 0;
        double maxc = -1e18;
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                        if (c[i][j] > maxc) {
                                maxc = c[i][j];
                                si = i;
                                sj = j;
                        }
                }
        }

        vector<vector<bool>> visited(n, vector<bool>(n, false));
        int ci = si, cj = sj;
        visited[ci][cj] = true;
        cout << ci << ' ' << cj << endl;

        vector<pair<int, int>> path;

        int moves = 1;
        int di[4] = {-1, 1, 0, 0}, dj[4] = {0, 0, -1, 1};
        while (moves < t) {
                int ni = -1, nj = -1;
                double best = -1e18;
                for (int d = 0; d < 4; d++) {
                        int ti = ci + di[d], tj = cj + dj[d];
                        if (ti < 0 || ti >= n || tj < 0 || tj >= n) continue;
                        if (visited[ti][tj]) continue;
                        if (c[ti][tj] > best) {
                                best = c[ti][tj];
                                ni = ti;
                                nj = tj;
                        }
                }
                if (ni == -1) break;
                ci = ni;
                cj = nj;
                visited[ci][cj] = true;
                path.emplace_back(ci, cj);
                moves++;
        }

        cout<<path.size()<<endl;
        for (auto [x, y] : path) {
                cout << x << ' ' << y << endl;
        }
}
0