제출 #960605

#제출 시각아이디문제언어결과실행 시간메모리
960605LmaoLmaoMecho (IOI09_mecho)C++14
0 / 100
3 ms604 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second using ll = long long; using ii = pair<int, int>; const int N = 1e6+5; const int INF = 1e9; ll d[1000][1000],m[1000][1000],n,s; char a[1000][1000]; ll dx[4]={1,0,0,-1}; ll dy[4]={0,1,-1,0}; ii pos,h; bool bfs(ll x) { queue<ii> q; q.push(pos); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { m[i][j]=0; } } while(!q.empty()) { if(d[pos.fi][pos.se]-x*s<=0) return 0; ii u=q.front(); q.pop(); for(int i=0;i<4;i++) { ii v={u.fi+dx[i],u.se+dy[i]}; if(v.fi<0 || v.fi>=n || v.se<0 || v.se>=n) continue; if(m[v.fi][v.se]==0 && a[v.fi][v.se]!='T' && d[v.fi][v.se]-x*s>m[u.fi][u.se]+1 && a[v.fi][v.se]!='M') { m[v.fi][v.se]=m[u.fi][u.se]+1; q.push(v); } } } if(m[h.fi][h.se]>0) return 1; else return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif queue<ii> q; cin >> n >> s; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin >> a[i][j]; if(a[i][j]=='H') { q.push({i,j}); } if(a[i][j]=='M') pos={i,j}; if(a[i][j]=='D') h={i,j}; } } while(!q.empty()) { ii u=q.front(); q.pop(); for(int i=0;i<4;i++) { ii v={u.fi+dx[i],u.se+dy[i]}; if(v.fi<0 || v.fi>=n || v.se<0 || v.se>=n) continue; if(d[v.fi][v.se]==0 && a[v.fi][v.se]!='T' && a[v.fi][v.se]!='H') { d[v.fi][v.se]=d[u.fi][u.se]+s; q.push(v); } } } ll l=0,r=1000000,ans=1; while(l<=r) { int m=(l+r)/2; if(bfs(m)) { ans=m; l=m+1; } else { r=m-1; } } cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

mecho.cpp: In function 'int main()':
mecho.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:49:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...