結果

問題 No.5024 魔法少女うなと宝集め
コンテスト
ユーザー てる
提出日時 2026-05-02 17:38:00
言語 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,111 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,613 ms
コンパイル使用メモリ 342,684 KB
実行使用メモリ 6,400 KB
スコア 540,000
最終ジャッジ日時 2026-05-02 17:38:11
合計ジャッジ時間 11,388 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60; // 10^18 より大きい
const int inf = 1<<30; // 10^9 より大きい
const long long MOD1 = 1000000007;
const long long MOD2 =  998244353;
typedef long long ll;
//a:97, A:65
const int dx[]={1,0,-1,0,-1,1,1,-1};
const int dy[]={0,1,0,-1,-1,-1,1,1};
const double PI = acos(-1);
#define Yes cout << "Yes\n"
#define No cout << "No\n"
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
// priority_queue<ll,vector<ll>,greater<ll>> q;
template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }

/*
好きなマスからスタート
同じマスを訪れない。
*/

int N=20,T=400;
int A[400][400];
vector<pair<int,int>> best_ans;
int best_score=-1;


void solve(int sy,int sx){
    int y=sy,x=sx; // 初期位置
    int score=A[y][x];
    vvi used(N,vector<int>(N,0));
    vector<pii> ans;
    ans.push_back({y,x});
    used[y][x]=1;
    for(int t=0;t<T;t++){
        int mx_y=-1,mx_x=-1;
        for(int i=0;i<4;i++){
            int ny=y+dy[i],nx=x+dx[i];
            if(ny<0||N<=ny||nx<0||N<=nx) continue;
            if(used[ny][nx]==1) continue;
            if(mx_y==-1){
                mx_y=ny;
                mx_x=nx;
            }else if(A[mx_y][mx_x]<A[ny][nx]){
                mx_y=ny;
                mx_x=nx;
            }
        }
        if(mx_y==-1){
            break;
        }else{
            ans.push_back({mx_y,mx_x});
            y=mx_y; x=mx_x;
            used[y][x]=1;
        }
    }
    
    if(best_score<score){
        best_score=score;
        best_ans=ans;
    }
    
    return;
}

int main(){
    int dummy; cin >> dummy >> 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++) solve(i,j);
    cout << best_ans.size() << "\n";
    for(auto v:best_ans) cout << v.first << " " << v.second << "\n";
}
0