結果
| 問題 | No.5024 魔法少女うなと宝集め |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-02 17:45:57 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 2,889 bytes |
| 記録 | |
| コンパイル時間 | 7,241 ms |
| コンパイル使用メモリ | 379,992 KB |
| 実行使用メモリ | 6,400 KB |
| スコア | 612,508 |
| 最終ジャッジ日時 | 2026-05-02 17:47:34 |
| 合計ジャッジ時間 | 14,850 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:59:20: warning: 'mi' may be used uninitialized [-Wmaybe-uninitialized]
59 | RANGE(i, mi, mi+bs) RANGE(j, mj, mj+bs) {
| ^
main.cpp:13:41: note: in definition of macro 'RANGE'
13 | #define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
| ^
main.cpp:48:9: note: 'mi' was declared here
48 | int mi, mj;
| ^~
main.cpp:59:40: warning: 'mj' may be used uninitialized [-Wmaybe-uninitialized]
59 | RANGE(i, mi, mi+bs) RANGE(j, mj, mj+bs) {
| ^
main.cpp:13:41: note: in definition of macro 'RANGE'
13 | #define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
| ^
main.cpp:48:13: note: 'mj' was declared here
48 | int mi, mj;
| ^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:64,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:62,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
from main.cpp:1:
In constructor 'constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U1 = int&; _U2 = int&; _T1 = int; _T2 = int]',
inlined from 'constexpr _Tp* std::construct_at(_Tp*, _Args&& ...) [with _Tp = pair<int, int>; _Args = {int&, int&}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_construct.h:110:9,
inlined from 'static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::pair<int, int>; _Args = {int&, int&}; _Tp = std::pair<int, int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/alloc_traits.h:676:21,
inlined from 'constexpr void std::vector<_Tp, _Alloc>::_M_realloc_append(_Args&& ...) [with _Args = {int&, int&
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using lnt = long long;
using Real = long double;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)
#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)
constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;
int main(){
summon_tourist;
int N, T; cin >> N >> T;
vector<vint> A(N, vint(N));
REP(i, N) REP(j, N) cin >> A[i][j];
int bs = min(3, (int)sqrt(T));
int mi, mj;
int mx = -1;
REP(i, N-bs+1) REP(j, N-bs+1) {
int sum = 0;
RANGE(k, i, i+bs) RANGE(l, j, j+bs) sum += A[k][l];
if(chmax(mx, sum)) {
mi = i; mj = j;
}
}
int si, sj;
mx = -1;
RANGE(i, mi, mi+bs) RANGE(j, mj, mj+bs) {
if(chmax(mx, A[i][j])) {
si = i; sj = j;
}
}
vector<pint> path;
path.emplace_back(si,sj);
vector<vector<bool>> vis(N, vector<bool>(N,false));
vis[si][sj] = true;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
for(int step = 1; step < T; step++){
int ci = path.back().first, cj = path.back().second;
int best_i = -1, best_j = -1, best_val = -BIG;
REP(d, 4){
int ni = ci + dx[d], nj = cj + dy[d];
if(ni<0 || ni>=N || nj<0 || nj>=N) continue;
int val = A[ni][nj];
if(!vis[ni][nj]){
if(chmax(best_val, val)){
best_i = ni; best_j = nj;
}
}
}
if(best_i == -1) break;
path.emplace_back(best_i,best_j);
vis[best_i][best_j]=true;
}
cout << path.size() << ln;
for(auto [i,j] : path) cout << i << ' ' << j << ln;
}