답안 #883156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883156 2023-12-04T16:25:32 Z Servant_of_the_Lord Mecho (IOI09_mecho) C++17
0 / 100
1000 ms 7616 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    ll x,y,z,a,b,c,d,e;
    cin>>x>>y;
    vector<string>v;
    vector<vector<ll>>w,u;
    for(ll i=0;i<x;i++)
    {
        string s;
        cin>>s;
        v.push_back(s);
        for(ll j=0;j<x;j++)
        {
            if(v[i][j]=='M')w.push_back({i,j});
            if(v[i][j]=='H')u.push_back({i,j});
            if(v[i][j]=='D')d=i,e=j;
            
        }
    }
    
    a=0,b=LLONG_MAX;
    while(a<b)
    {
        ll m=a+(b-a+1)/2;
        bool o=false;
        vector<vector<ll>>q,r;
        vector<vector<bool>>t(x,vector<bool>(x)),s(x,vector<bool>(x));
        
        function<void()>bees=[&]()
        {
            vector<vector<ll>>q2;
            function<void(ll,ll)>ba=[&](ll a,ll b)
            {
                if(a>=0&&a<x&&b>=0&&b<x&&t[a][b]==false)
                {
                    q2.push_back({a,b});
                    t[a][b]=true;
                }
                
            };
            for(ll i=0;i<q.size();i++)
            {
                ba(q[i][0]-1,q[i][1]);
                ba(q[i][0]+1,q[i][1]);
                ba(q[i][0],q[i][1]-1);
                ba(q[i][0],q[i][1]+1);
            }
            q2.swap(q);
        };
        function<void()>bear=[&]()
        {
            vector<vector<ll>>r2;
            function<void(ll,ll)>ba=[&](ll a,ll b)
            {
                if(a>=0&&a<x&&b>=0&&b<x&&t[a][b]==false&&s[a][b]==false&&(v[a][b]=='G'||v[a][b]=='D'))
                {
                    r2.push_back({a,b});
                    if(a==d&&b==e)o=true;
                }
                
            };
            for(ll i=0;i<r.size();i++)
            {
                ba(r[i][0]-1,r[i][1]);
                ba(r[i][0]+1,r[i][1]);
                ba(r[i][0],r[i][1]-1);
                ba(r[i][0],r[i][1]+1);
            }
            r2.swap(r);
        };
        for(auto i:w)r.push_back(i);
        for(auto i:u)q.push_back(i);
        for(ll i=0;i<m;i++)
        {
            bees();
        }
        while(r.size())
        {
            
            for(ll i=0;i<y;i++)bear();
            bees();
            vector<vector<ll>>r2;
            for(ll i=0;i<r.size();i++)
            {
                if(!t[r[i][0]][r[i][1]])
                {
                    r2.push_back(r[i]);
                    s[r[i][0]][r[i][1]]=true;
                }
            }
            r2.swap(r);
        }
        if(o)a=m;
        else b=m-1;
    }
    cout<<a<<'\n';
}

Compilation message

mecho.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~
mecho.cpp: In lambda function:
mecho.cpp:49:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             for(ll i=0;i<q.size();i++)
      |                        ~^~~~~~~~~
mecho.cpp: In lambda function:
mecho.cpp:70:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(ll i=0;i<r.size();i++)
      |                        ~^~~~~~~~~
mecho.cpp: In function 'int main()':
mecho.cpp:91:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |             for(ll i=0;i<r.size();i++)
      |                        ~^~~~~~~~~
mecho.cpp:11:12: warning: unused variable 'z' [-Wunused-variable]
   11 |     ll x,y,z,a,b,c,d,e;
      |            ^
mecho.cpp:11:18: warning: unused variable 'c' [-Wunused-variable]
   11 |     ll x,y,z,a,b,c,d,e;
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1028 ms 344 KB Time limit exceeded
2 Execution timed out 1046 ms 348 KB Time limit exceeded
3 Execution timed out 1064 ms 348 KB Time limit exceeded
4 Execution timed out 1053 ms 348 KB Time limit exceeded
5 Execution timed out 1044 ms 344 KB Time limit exceeded
6 Execution timed out 1032 ms 344 KB Time limit exceeded
7 Execution timed out 1018 ms 4008 KB Time limit exceeded
8 Execution timed out 1041 ms 344 KB Time limit exceeded
9 Execution timed out 1020 ms 348 KB Time limit exceeded
10 Execution timed out 1050 ms 348 KB Time limit exceeded
11 Execution timed out 1026 ms 344 KB Time limit exceeded
12 Execution timed out 1037 ms 348 KB Time limit exceeded
13 Execution timed out 1075 ms 348 KB Time limit exceeded
14 Execution timed out 1063 ms 348 KB Time limit exceeded
15 Execution timed out 1039 ms 344 KB Time limit exceeded
16 Execution timed out 1022 ms 344 KB Time limit exceeded
17 Execution timed out 1014 ms 344 KB Time limit exceeded
18 Execution timed out 1082 ms 344 KB Time limit exceeded
19 Execution timed out 1066 ms 348 KB Time limit exceeded
20 Execution timed out 1006 ms 344 KB Time limit exceeded
21 Execution timed out 1016 ms 344 KB Time limit exceeded
22 Execution timed out 1052 ms 348 KB Time limit exceeded
23 Execution timed out 1069 ms 600 KB Time limit exceeded
24 Execution timed out 1084 ms 344 KB Time limit exceeded
25 Execution timed out 1069 ms 600 KB Time limit exceeded
26 Execution timed out 1050 ms 348 KB Time limit exceeded
27 Execution timed out 1051 ms 348 KB Time limit exceeded
28 Execution timed out 1036 ms 348 KB Time limit exceeded
29 Execution timed out 1016 ms 348 KB Time limit exceeded
30 Execution timed out 1016 ms 348 KB Time limit exceeded
31 Execution timed out 1058 ms 348 KB Time limit exceeded
32 Execution timed out 1048 ms 348 KB Time limit exceeded
33 Execution timed out 1064 ms 604 KB Time limit exceeded
34 Execution timed out 1071 ms 840 KB Time limit exceeded
35 Execution timed out 1067 ms 860 KB Time limit exceeded
36 Execution timed out 1035 ms 600 KB Time limit exceeded
37 Execution timed out 1065 ms 860 KB Time limit exceeded
38 Execution timed out 1016 ms 856 KB Time limit exceeded
39 Execution timed out 1062 ms 860 KB Time limit exceeded
40 Execution timed out 1016 ms 856 KB Time limit exceeded
41 Execution timed out 1065 ms 1116 KB Time limit exceeded
42 Execution timed out 1036 ms 856 KB Time limit exceeded
43 Execution timed out 1057 ms 1116 KB Time limit exceeded
44 Execution timed out 1052 ms 1116 KB Time limit exceeded
45 Execution timed out 1051 ms 860 KB Time limit exceeded
46 Execution timed out 1057 ms 1116 KB Time limit exceeded
47 Execution timed out 1031 ms 1296 KB Time limit exceeded
48 Execution timed out 1064 ms 1116 KB Time limit exceeded
49 Execution timed out 1032 ms 1372 KB Time limit exceeded
50 Execution timed out 1064 ms 1372 KB Time limit exceeded
51 Execution timed out 1045 ms 1116 KB Time limit exceeded
52 Execution timed out 1061 ms 1628 KB Time limit exceeded
53 Execution timed out 1040 ms 1636 KB Time limit exceeded
54 Execution timed out 1065 ms 1116 KB Time limit exceeded
55 Execution timed out 1024 ms 1624 KB Time limit exceeded
56 Execution timed out 1022 ms 1848 KB Time limit exceeded
57 Execution timed out 1062 ms 1372 KB Time limit exceeded
58 Execution timed out 1070 ms 1972 KB Time limit exceeded
59 Execution timed out 1061 ms 1884 KB Time limit exceeded
60 Execution timed out 1029 ms 1368 KB Time limit exceeded
61 Execution timed out 1037 ms 2136 KB Time limit exceeded
62 Execution timed out 1029 ms 2192 KB Time limit exceeded
63 Execution timed out 1037 ms 1632 KB Time limit exceeded
64 Execution timed out 1054 ms 2152 KB Time limit exceeded
65 Execution timed out 1047 ms 1368 KB Time limit exceeded
66 Execution timed out 1072 ms 1628 KB Time limit exceeded
67 Execution timed out 1072 ms 1372 KB Time limit exceeded
68 Execution timed out 1042 ms 5216 KB Time limit exceeded
69 Execution timed out 1084 ms 5112 KB Time limit exceeded
70 Execution timed out 1051 ms 5116 KB Time limit exceeded
71 Execution timed out 1078 ms 4356 KB Time limit exceeded
72 Execution timed out 1032 ms 5252 KB Time limit exceeded
73 Execution timed out 1022 ms 7604 KB Time limit exceeded
74 Execution timed out 1061 ms 7596 KB Time limit exceeded
75 Execution timed out 1056 ms 7616 KB Time limit exceeded
76 Execution timed out 1063 ms 7612 KB Time limit exceeded
77 Execution timed out 1048 ms 7608 KB Time limit exceeded
78 Execution timed out 1053 ms 5592 KB Time limit exceeded
79 Execution timed out 1060 ms 5592 KB Time limit exceeded
80 Execution timed out 1018 ms 5844 KB Time limit exceeded
81 Execution timed out 1054 ms 5584 KB Time limit exceeded
82 Execution timed out 1036 ms 5844 KB Time limit exceeded
83 Execution timed out 1046 ms 5584 KB Time limit exceeded
84 Execution timed out 1051 ms 5612 KB Time limit exceeded
85 Execution timed out 1022 ms 5576 KB Time limit exceeded
86 Execution timed out 1070 ms 5592 KB Time limit exceeded
87 Execution timed out 1012 ms 5836 KB Time limit exceeded
88 Execution timed out 1043 ms 5172 KB Time limit exceeded
89 Execution timed out 1039 ms 5156 KB Time limit exceeded
90 Execution timed out 1049 ms 5160 KB Time limit exceeded
91 Execution timed out 1016 ms 5156 KB Time limit exceeded
92 Execution timed out 1040 ms 5156 KB Time limit exceeded