답안 #442195

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442195 2021-07-07T09:23:23 Z Haidara Mecho (IOI09_mecho) C++17
1 / 100
1000 ms 12360 KB
/* * * * * * * * * *\
 * Author: Haidara *
 * LANG: C++17     *
 * PROB:           *
\* * * * * * * * * */
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define rep(i,x,n) for(int i=x;i<(n);i++)
#define FOR(i,n) rep(i,0,n)
#define per(i,x,n) for(int i=x;i>(n);i--)
#define ROF(i,x) for(int i=x;i>=0;i--)
#define v(i) vector< i >
#define p(i,j) pair< i , j >
#define pii pair<int,int>
#define m(i,j) map< i , j >
#define um(i,j) unordered_map< i , j >
#define pq(i) priority_queue< i >
#define ff first
#define all(x) x.begin(),x.end()
#define ss second
#define pp push_back
using namespace std;
void SIO(string name="")
{
    if(name!="")
    {
        freopen((name+".in").c_str(),"r",stdin);
        freopen((name+".out").c_str(),"w",stdout);
    }
}
const int inf=1LL<<60LL;
const int mod=1e9+7;
const int maxn=808;
int n,foot;
pii Mecho,House;
char a[maxn][maxn];
bool vis[maxn][maxn];
queue<pii>q;
v(v(int)) dist;
int dx[] {-1,1,0,0};
int dy[] {0,0,-1,1};
bool valid(int x,int y)
{
    return x>=0&&y>=0&&x<n&&y<n&&(a[x][y]=='G'||a[x][y]=='D');
}
int jump[maxn][maxn];
bool finish=0;
void solve()
{
    while(q.size())
    {
        pii f=q.front();
        q.pop();
        FOR(i,4)
        {
            int x=f.ff+dx[i],y=f.ss+dy[i];
            if(valid(x,y))
            {
                if(!vis[x][y])
                {
                    vis[x][y]=1;
                    if(jump[f.ff][f.ss]){
                        q.push({x,y});
                        dist[x][y]=dist[f.ff][f.ss];
                        jump[x][y]=jump[f.ff][f.ss]-1;
                    } else {
                        q.push({x,y});
                        dist[x][y]=dist[f.ff][f.ss]+1;
                        if(finish)
                            jump[x][y]=foot;
                    }
                }
                else if(!finish&&dist[x][y]>dist[f.ff][f.ss]+1)
                {
                    dist[x][y]=dist[f.ff][f.ss]+1;
                    q.push({x,y});
                }
            }
        }
    }
}
signed main()
{
    SIO("");
    cin>>n>>foot;
    dist.resize(maxn);
    FOR(i,maxn)
    dist[i].resize(maxn);
    FOR(i,n)
    FOR(j,n)
    {
        cin>>a[i][j];
        dist[i][j]=inf;
        if(a[i][j]=='M')
            Mecho= {i,j};
        else if(a[i][j]=='H')
            q.push({i,j}),vis[i][j]=1,dist[i][j]=0;
        else if(a[i][j]=='T')
            vis[i][j]=1;
        else if(a[i][j]=='D')
            House= {i,j};
    }
    solve();
    int len=dist[House.ff][House.ss];
    int l=1,r=inf,ans=-1;
    finish=1;
    while(l<=r)
    {
        int mid=l+(r-l)/2;
        FOR(i,maxn)
        FOR(j,maxn)
        dist[i][j]=inf,vis[i][j]=0,jump[i][j]=0;
        dist[Mecho.ff][Mecho.ss]=mid;
        jump[Mecho.ff][Mecho.ss]=foot;
        q.push(Mecho);
        solve();
        if(dist[House.ff][House.ss]<len)
            ans=max(ans,mid),l=mid+1;
        else
            r=mid-1;
    }
    cout<<ans;
}

Compilation message

mecho.cpp: In function 'void SIO(std::string)':
mecho.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen((name+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((name+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 93 ms 11084 KB Output isn't correct
2 Correct 91 ms 11084 KB Output is correct
3 Incorrect 91 ms 11084 KB Output isn't correct
4 Incorrect 93 ms 11332 KB Output isn't correct
5 Incorrect 92 ms 11172 KB Output isn't correct
6 Incorrect 91 ms 11172 KB Output isn't correct
7 Execution timed out 1081 ms 11984 KB Time limit exceeded
8 Incorrect 96 ms 11204 KB Output isn't correct
9 Incorrect 94 ms 11196 KB Output isn't correct
10 Incorrect 92 ms 11084 KB Output isn't correct
11 Incorrect 94 ms 11084 KB Output isn't correct
12 Incorrect 96 ms 11232 KB Output isn't correct
13 Incorrect 98 ms 11216 KB Output isn't correct
14 Incorrect 101 ms 11212 KB Output isn't correct
15 Incorrect 91 ms 11180 KB Output isn't correct
16 Incorrect 92 ms 11084 KB Output isn't correct
17 Incorrect 92 ms 11084 KB Output isn't correct
18 Incorrect 92 ms 11188 KB Output isn't correct
19 Incorrect 92 ms 11188 KB Output isn't correct
20 Incorrect 95 ms 11184 KB Output isn't correct
21 Incorrect 96 ms 11196 KB Output isn't correct
22 Incorrect 93 ms 11212 KB Output isn't correct
23 Incorrect 94 ms 11212 KB Output isn't correct
24 Incorrect 98 ms 11220 KB Output isn't correct
25 Incorrect 96 ms 11212 KB Output isn't correct
26 Incorrect 95 ms 11172 KB Output isn't correct
27 Incorrect 100 ms 11212 KB Output isn't correct
28 Incorrect 98 ms 11236 KB Output isn't correct
29 Incorrect 100 ms 11212 KB Output isn't correct
30 Incorrect 98 ms 11224 KB Output isn't correct
31 Incorrect 101 ms 11212 KB Output isn't correct
32 Incorrect 104 ms 11220 KB Output isn't correct
33 Incorrect 218 ms 11456 KB Output isn't correct
34 Incorrect 217 ms 11340 KB Output isn't correct
35 Incorrect 315 ms 11392 KB Output isn't correct
36 Incorrect 254 ms 11524 KB Output isn't correct
37 Incorrect 255 ms 11468 KB Output isn't correct
38 Incorrect 399 ms 11600 KB Output isn't correct
39 Incorrect 299 ms 11424 KB Output isn't correct
40 Incorrect 316 ms 11524 KB Output isn't correct
41 Incorrect 489 ms 11548 KB Output isn't correct
42 Incorrect 342 ms 11560 KB Output isn't correct
43 Incorrect 334 ms 11560 KB Output isn't correct
44 Incorrect 587 ms 11588 KB Output isn't correct
45 Incorrect 392 ms 11588 KB Output isn't correct
46 Incorrect 400 ms 11600 KB Output isn't correct
47 Incorrect 714 ms 11544 KB Output isn't correct
48 Incorrect 436 ms 11644 KB Output isn't correct
49 Incorrect 489 ms 11648 KB Output isn't correct
50 Incorrect 841 ms 11660 KB Output isn't correct
51 Incorrect 526 ms 11680 KB Output isn't correct
52 Incorrect 537 ms 11684 KB Output isn't correct
53 Incorrect 928 ms 11772 KB Output isn't correct
54 Incorrect 585 ms 11716 KB Output isn't correct
55 Incorrect 608 ms 11712 KB Output isn't correct
56 Execution timed out 1078 ms 11716 KB Time limit exceeded
57 Incorrect 676 ms 11696 KB Output isn't correct
58 Incorrect 651 ms 11760 KB Output isn't correct
59 Execution timed out 1099 ms 11716 KB Time limit exceeded
60 Incorrect 722 ms 11792 KB Output isn't correct
61 Incorrect 718 ms 11844 KB Output isn't correct
62 Execution timed out 1098 ms 11748 KB Time limit exceeded
63 Execution timed out 1096 ms 11812 KB Time limit exceeded
64 Execution timed out 1082 ms 11704 KB Time limit exceeded
65 Execution timed out 1084 ms 11784 KB Time limit exceeded
66 Execution timed out 1062 ms 11700 KB Time limit exceeded
67 Execution timed out 1099 ms 11736 KB Time limit exceeded
68 Execution timed out 1078 ms 11856 KB Time limit exceeded
69 Execution timed out 1061 ms 11924 KB Time limit exceeded
70 Execution timed out 1080 ms 11824 KB Time limit exceeded
71 Execution timed out 1069 ms 11804 KB Time limit exceeded
72 Execution timed out 1100 ms 11788 KB Time limit exceeded
73 Execution timed out 1073 ms 12360 KB Time limit exceeded
74 Execution timed out 1055 ms 12356 KB Time limit exceeded
75 Execution timed out 1064 ms 12272 KB Time limit exceeded
76 Execution timed out 1085 ms 12256 KB Time limit exceeded
77 Execution timed out 1090 ms 12268 KB Time limit exceeded
78 Execution timed out 1097 ms 12212 KB Time limit exceeded
79 Execution timed out 1075 ms 12312 KB Time limit exceeded
80 Execution timed out 1085 ms 12272 KB Time limit exceeded
81 Execution timed out 1089 ms 12200 KB Time limit exceeded
82 Execution timed out 1089 ms 12204 KB Time limit exceeded
83 Execution timed out 1090 ms 12100 KB Time limit exceeded
84 Execution timed out 1066 ms 12100 KB Time limit exceeded
85 Execution timed out 1086 ms 12100 KB Time limit exceeded
86 Execution timed out 1093 ms 12120 KB Time limit exceeded
87 Execution timed out 1073 ms 12116 KB Time limit exceeded
88 Execution timed out 1073 ms 12232 KB Time limit exceeded
89 Execution timed out 1077 ms 12100 KB Time limit exceeded
90 Execution timed out 1085 ms 12124 KB Time limit exceeded
91 Execution timed out 1077 ms 12128 KB Time limit exceeded
92 Execution timed out 1050 ms 12128 KB Time limit exceeded