제출 #697664

#제출 시각아이디문제언어결과실행 시간메모리
697664aminMecho (IOI09_mecho)C++14
23 / 100
44 ms11796 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int b[4]={0,0,-1,1}; int c[4]={-1,1,0,0}; char mo[4]={'L','R','U','D'}; int main() { /* freopen("piggyback.in","r",stdin); freopen("piggyback.out","w",stdout);*/ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,k; cin>>n>>k; m=n; int enx,eny; char a[n][m]; int val[n][m]; char pre[n][m]; pair<int,int>p[n][m]; queue<pair<int,int> >q; int x,y; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { val[i][j]=1e9; cin>>a[i][j]; if(a[i][j]=='M') { x=i; y=j; } if(a[i][j]=='D') { enx=i; eny=j; } if(a[i][j]=='H') { q.push({i,j}); val[i][j]=1; } } } while(!q.empty()) { int xx=q.front().first; int yy=q.front().second; q.pop(); for(int i=0;i<4;i++) { int xxx=xx+b[i]; int yyy=yy+c[i]; if(xxx<0||xxx>=n||yyy<0||yyy>=m) continue; if(val[xxx][yyy]==1e9&&a[xxx][yyy]!='T') { val[xxx][yyy]=val[xx][yy]+1; q.push({xxx,yyy}); } } } int vall[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { vall[i][j]=0; } } /* for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cout<<val[i][j]<<' '; } cout<<endl; }*/ int l=0; int r=n*m; int jj=0; while((l+1)<r) { jj=0; q.push({x,y}); int ansx=-1,ansy=-1; int mi=(l+r)/2; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { vall[x][j]=0; } } vall[x][y]=1; while(!q.empty()) { int xx=q.front().first; int yy=q.front().second; /* if(l==0) { cout<<xx<<' '<<yy<<endl; }*/ // cout<<xx<<' '<<yy<<endl; q.pop(); if(xx==enx&&yy==eny) { jj=1; break; } for(int i=0;i<4;i++) { int xxx=xx+b[i]; int yyy=yy+c[i]; if(xxx<0||xxx>=n||yyy<0||yyy>=m) continue; if(vall[xxx][yyy]==0&&a[xxx][yyy]!='T') { vall[xxx][yyy]=vall[xx][yy]+1; if((-(vall[xxx][yyy]-1+k)/k+val[xxx][yyy]-1)>=mi) { q.push({xxx,yyy}); } } } } if(jj==1) { l=mi; }else r=mi; } cout<<l<<endl; }

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

mecho.cpp: In function 'int main()':
mecho.cpp:99:8: warning: unused variable 'ansx' [-Wunused-variable]
   99 |    int ansx=-1,ansy=-1;
      |        ^~~~
mecho.cpp:99:16: warning: unused variable 'ansy' [-Wunused-variable]
   99 |    int ansx=-1,ansy=-1;
      |                ^~~~
mecho.cpp:25:9: warning: unused variable 'pre' [-Wunused-variable]
   25 |    char pre[n][m];
      |         ^~~
mecho.cpp:26:17: warning: unused variable 'p' [-Wunused-variable]
   26 |    pair<int,int>p[n][m];
      |                 ^
mecho.cpp:121:20: warning: 'eny' may be used uninitialized in this function [-Wmaybe-uninitialized]
  121 |      if(xx==enx&&yy==eny)
      |                  ~~^~~~~
mecho.cpp:121:11: warning: 'enx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  121 |      if(xx==enx&&yy==eny)
      |         ~~^~~~~
mecho.cpp:108:14: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
  108 |    vall[x][y]=1;
      |    ~~~~~~~~~~^~
mecho.cpp:108:14: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...