結果
| 問題 | No.5024 魔法少女うなと宝集め |
| コンテスト | |
| ユーザー |
てる
|
| 提出日時 | 2026-05-02 17:52:23 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 3,154 bytes |
| 記録 | |
| コンパイル時間 | 3,627 ms |
| コンパイル使用メモリ | 348,312 KB |
| 実行使用メモリ | 6,400 KB |
| スコア | 826,828 |
| 最終ジャッジ日時 | 2026-05-02 17:52:47 |
| 合計ジャッジ時間 | 6,660 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#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,ans2;
vvi best_used;
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;
best_used=used;
}
return;
}
void solve2(){
auto [y,x]=best_ans[0];
vvi used=best_used;
used[y][x]=1;
T-=(int)best_ans.size();
for(int t=1;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{
ans2.push_back({mx_y,mx_x});
y=mx_y; x=mx_x;
used[y][x]=1;
}
}
return;
}
int main(){
int dummy; cin >> dummy >> T;
int TT=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);
solve2();
cout << min(TT,(int)best_ans.size()+(int)ans2.size()) << "\n";
int cnt=0;
for(int i=best_ans.size()-1;i>=0;i--){
cnt++;
cout << best_ans[i].first << " " << best_ans[i].second << "\n";
if(cnt==TT) return 0;
}
for(auto [y,x]:ans2){
cnt++;
cout << y << " " << x << "\n";
if(cnt==TT) return 0;
}
}
てる