結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
LayCurse
|
| 提出日時 | 2020-01-17 22:45:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,328 bytes |
| コンパイル時間 | 2,792 ms |
| コンパイル使用メモリ | 222,964 KB |
| 最終ジャッジ日時 | 2025-01-08 19:01:20 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 TLE * 13 |
ソースコード
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline void rd(char &c){
int i;
for(;;){
i = getchar_unlocked();
if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
break;
}
}
c = i;
}
inline int rd(char c[]){
int i;
int sz = 0;
for(;;){
i = getchar_unlocked();
if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
break;
}
}
c[sz++] = i;
for(;;){
i = getchar_unlocked();
if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
break;
}
c[sz++] = i;
}
c[sz]='\0';
return sz;
}
inline void wt_L(char a){
putchar_unlocked(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
putchar_unlocked('-');
}
while(s--){
putchar_unlocked(f[s]+'0');
}
}
int X;
int Y;
char A[2000][2002];
priority_queue<pair<int,pair<int,int>>> q;
set<pair<int,int>> alr;
int main(){
int sx;
int sy;
int nx;
int ny;
int dist;
int ndist;
int cost;
int ncost;
int d;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
rd(X);
rd(Y);
{
int Lj4PdHRW;
for(Lj4PdHRW=(0);Lj4PdHRW<(X);Lj4PdHRW++){
rd(A[Lj4PdHRW]);
}
}
q.push(make_pair(-1,make_pair((X-1)*Y+Y-1,1)));
for(;;){
dist = q.top().first;
sx = q.top().second.first / Y;
sy = q.top().second.first % Y;
cost = q.top().second.second;
if(sx==0 && sy==0){
wt_L(-dist-cost);
wt_L('\n');
return 0;
}
q.pop();
if(alr.count(make_pair(sx*Y+sy, cost))){
continue;
}
alr.insert(make_pair(sx*Y+sy, cost));
for(d=(0);d<(4);d++){
nx = sx + dx[d];
ny = sy + dy[d];
if(nx < 0 || ny < 0 || nx >= X || ny >= Y){
continue;
}
if(A[nx][ny]=='k'){
ncost = cost +1;
}
else{
ncost = cost +0;
}
ndist = dist - ncost;
q.push(make_pair(ndist,make_pair(nx*Y+ny,ncost)));
}
}
return 0;
}
// cLay varsion 20200112-1
// --- original code ---
// int X, Y;
// char A[2000][2002];
//
// priority_queue<pair<int,pair<int,int>>> q;
// set<pair<int,int>> alr;
//
// {
// int sx, sy, nx, ny, dist, ndist, cost, ncost, d;
// int dx[4] = {-1,1,0,0};
// int dy[4] = {0,0,-1,1};
// rd(X,Y,A(X));
// q.push(make_pair(-1,make_pair((X-1)*Y+Y-1,1)));
// for(;;){
// dist = q.top().first;
// sx = q.top().second.first / Y;
// sy = q.top().second.first % Y;
// cost = q.top().second.second;
// if(sx==0 && sy==0) wt(-dist-cost), return 0;
// q.pop();
// if(alr.count(make_pair(sx*Y+sy, cost))) continue;
// alr.insert(make_pair(sx*Y+sy, cost));
// rep(d,4){
// nx = sx + dx[d];
// ny = sy + dy[d];
// if(nx < 0 || ny < 0 || nx >= X || ny >= Y) continue;
// ncost = cost + if[A[nx][ny]=='k', 1, 0];
// ndist = dist - ncost;
// q.push(make_pair(ndist,make_pair(nx*Y+ny,ncost)));
// }
// }
// }
LayCurse