# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1100020 |
2024-10-12T11:54:49 Z |
asli_bg |
Mecho (IOI09_mecho) |
C++11 |
|
1000 ms |
26452 KB |
#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define inset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vii;
#define cont(x) for(auto el:x) {cout<<el<<' ';} cout<<endl;
//#define endl '\n'
#define contp(x) for(auto el:x) {cout<<el.fi<<'-'<<el.se<<' ';} cout<<endl;
#define pb push_back
#define sp <<' '<<
#define DEBUG(x) {cout<<(#x) sp x<<endl;}
const int MAXN=805;
const int INF=1e9;
int n,s;
vector<string> grid;
set<pii> ari;
int mark[MAXN][MAXN];
set<pii> hive;
pii bas,son;
int yon1[4]={1,-1,0,0};
int yon2[4]={0,0,-1,1};
//sag, sol, asagi, yukari
bool isvalid(int x,int y,bool f){
if(x>=n or y>=n or x<0 or y<0) return false;
if(f){
if(grid[x][y]!='G' and grid[x][y]!='M') return false;
if(hive.count({x,y})) return false;
}
else{
if(grid[x][y]!='G' and grid[x][y]!='D') return false;
}
return true;
}
bool check(int deg){
//düz shortest path bfs
vector<vb> vis(n+1, vb(n+1,false));
queue<pair<pii,int>> q;
if(mark[bas.fi][bas.se]<deg) return false;
q.push({bas,0});
vis[bas.fi][bas.se]=true;
//cout<<"DEEEEEG" sp deg<<endl;
while(!q.empty()){
auto el=q.front();
q.pop();
int adim=el.se;
int x=el.fi.fi;
int y=el.fi.se;
//cout<<"control" sp adim sp x sp y<<endl;
FOR(i,4){
int yenix=x+yon1[i];
int yeniy=y+yon2[i];
if(!isvalid(yenix,yeniy,false)) continue;
if(vis[yenix][yeniy]) continue;
int sure=adim/s;
//DEBUG(sure);
//DEBUG(yenix);
//DEBUG(yeniy);
if(mark[yenix][yeniy]<deg+sure) continue;
if((adim+1)%s==0){
if(mark[yenix][yeniy]==deg+sure) continue;
}
q.push({{yenix,yeniy},adim+1});
vis[yenix][yeniy]=true;
}
}
return vis[son.fi][son.se];
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>s;
grid.resize(n);
FOR(i,n) cin>>grid[i];
FOR(i,n){
FOR(j,n){
if(grid[i][j]=='H'){
hive.insert({i,j});
mark[i][j]=0;
}
if(grid[i][j]=='M') {
bas={i,j};
}
if(grid[i][j]=='D'){
son={i,j};
mark[i][j]=INF;
}
}
}
int mx=0;
for(int i=0;true;i++){ //x kez ilerle
set<pii> tut;
for(auto el:hive){
FOR(i,4){
int yenix=el.fi+yon1[i];
int yeniy=el.se+yon2[i];
if(isvalid(yenix,yeniy,true)){
tut.insert({yenix,yeniy});
}
}
}
if(tut.empty()) break;
mx=i;
for(auto el:tut){
mark[el.fi][el.se]=i+1;
hive.insert(el);
}
}
/*FOR(i,n){
FOR(j,n) cout<<mark[i][j]<<' ';
cout<<endl;
}
cout<<endl;*/
//check(1);
int l=0;
int r=mx+1;
while(l+1<r){
int mid=(l+r)/2;
if(check(mid)) l=mid;
else r=mid;
}
cout<<l-1<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
1034 ms |
21840 KB |
Time limit exceeded |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
32 ms |
2748 KB |
Output isn't correct |
13 |
Correct |
9 ms |
2652 KB |
Output is correct |
14 |
Correct |
17 ms |
2768 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
7 ms |
2652 KB |
Output is correct |
20 |
Correct |
3 ms |
2648 KB |
Output is correct |
21 |
Correct |
16 ms |
2660 KB |
Output is correct |
22 |
Correct |
9 ms |
2652 KB |
Output is correct |
23 |
Correct |
52 ms |
2640 KB |
Output is correct |
24 |
Correct |
24 ms |
2648 KB |
Output is correct |
25 |
Correct |
126 ms |
2644 KB |
Output is correct |
26 |
Correct |
63 ms |
2680 KB |
Output is correct |
27 |
Correct |
190 ms |
2576 KB |
Output is correct |
28 |
Correct |
90 ms |
2708 KB |
Output is correct |
29 |
Correct |
259 ms |
2644 KB |
Output is correct |
30 |
Correct |
132 ms |
2728 KB |
Output is correct |
31 |
Correct |
351 ms |
2648 KB |
Output is correct |
32 |
Correct |
163 ms |
2708 KB |
Output is correct |
33 |
Execution timed out |
1072 ms |
2696 KB |
Time limit exceeded |
34 |
Execution timed out |
1034 ms |
3156 KB |
Time limit exceeded |
35 |
Execution timed out |
1058 ms |
6688 KB |
Time limit exceeded |
36 |
Execution timed out |
1032 ms |
2896 KB |
Time limit exceeded |
37 |
Execution timed out |
1052 ms |
5388 KB |
Time limit exceeded |
38 |
Execution timed out |
1057 ms |
9012 KB |
Time limit exceeded |
39 |
Execution timed out |
1085 ms |
2856 KB |
Time limit exceeded |
40 |
Execution timed out |
1042 ms |
5200 KB |
Time limit exceeded |
41 |
Execution timed out |
1035 ms |
9044 KB |
Time limit exceeded |
42 |
Execution timed out |
1070 ms |
2900 KB |
Time limit exceeded |
43 |
Execution timed out |
1054 ms |
3080 KB |
Time limit exceeded |
44 |
Execution timed out |
1055 ms |
9300 KB |
Time limit exceeded |
45 |
Execution timed out |
1012 ms |
2860 KB |
Time limit exceeded |
46 |
Execution timed out |
1061 ms |
3344 KB |
Time limit exceeded |
47 |
Execution timed out |
1098 ms |
9552 KB |
Time limit exceeded |
48 |
Execution timed out |
1031 ms |
3044 KB |
Time limit exceeded |
49 |
Execution timed out |
1071 ms |
3412 KB |
Time limit exceeded |
50 |
Execution timed out |
1044 ms |
9616 KB |
Time limit exceeded |
51 |
Execution timed out |
1055 ms |
3016 KB |
Time limit exceeded |
52 |
Execution timed out |
1040 ms |
3324 KB |
Time limit exceeded |
53 |
Execution timed out |
1045 ms |
9812 KB |
Time limit exceeded |
54 |
Execution timed out |
1022 ms |
1104 KB |
Time limit exceeded |
55 |
Execution timed out |
1022 ms |
1360 KB |
Time limit exceeded |
56 |
Execution timed out |
1067 ms |
9812 KB |
Time limit exceeded |
57 |
Execution timed out |
1038 ms |
1392 KB |
Time limit exceeded |
58 |
Execution timed out |
1047 ms |
1360 KB |
Time limit exceeded |
59 |
Execution timed out |
1028 ms |
10172 KB |
Time limit exceeded |
60 |
Execution timed out |
1039 ms |
1360 KB |
Time limit exceeded |
61 |
Execution timed out |
1060 ms |
1488 KB |
Time limit exceeded |
62 |
Execution timed out |
1058 ms |
10832 KB |
Time limit exceeded |
63 |
Execution timed out |
1044 ms |
8232 KB |
Time limit exceeded |
64 |
Execution timed out |
1087 ms |
4944 KB |
Time limit exceeded |
65 |
Execution timed out |
1059 ms |
4948 KB |
Time limit exceeded |
66 |
Execution timed out |
1040 ms |
8464 KB |
Time limit exceeded |
67 |
Execution timed out |
1049 ms |
5476 KB |
Time limit exceeded |
68 |
Execution timed out |
1094 ms |
19004 KB |
Time limit exceeded |
69 |
Execution timed out |
1079 ms |
18784 KB |
Time limit exceeded |
70 |
Execution timed out |
1079 ms |
19016 KB |
Time limit exceeded |
71 |
Execution timed out |
1064 ms |
19052 KB |
Time limit exceeded |
72 |
Execution timed out |
1082 ms |
19152 KB |
Time limit exceeded |
73 |
Execution timed out |
1081 ms |
26452 KB |
Time limit exceeded |
74 |
Execution timed out |
1072 ms |
26448 KB |
Time limit exceeded |
75 |
Execution timed out |
1077 ms |
26196 KB |
Time limit exceeded |
76 |
Execution timed out |
1083 ms |
26412 KB |
Time limit exceeded |
77 |
Execution timed out |
1038 ms |
26192 KB |
Time limit exceeded |
78 |
Execution timed out |
1020 ms |
25424 KB |
Time limit exceeded |
79 |
Execution timed out |
1075 ms |
25684 KB |
Time limit exceeded |
80 |
Execution timed out |
1064 ms |
25684 KB |
Time limit exceeded |
81 |
Execution timed out |
1067 ms |
25628 KB |
Time limit exceeded |
82 |
Execution timed out |
1071 ms |
25684 KB |
Time limit exceeded |
83 |
Execution timed out |
1058 ms |
25940 KB |
Time limit exceeded |
84 |
Execution timed out |
1059 ms |
25996 KB |
Time limit exceeded |
85 |
Execution timed out |
1043 ms |
25992 KB |
Time limit exceeded |
86 |
Execution timed out |
1066 ms |
25980 KB |
Time limit exceeded |
87 |
Execution timed out |
1071 ms |
25940 KB |
Time limit exceeded |
88 |
Execution timed out |
1047 ms |
25504 KB |
Time limit exceeded |
89 |
Execution timed out |
1058 ms |
25428 KB |
Time limit exceeded |
90 |
Execution timed out |
1058 ms |
25424 KB |
Time limit exceeded |
91 |
Execution timed out |
1056 ms |
25568 KB |
Time limit exceeded |
92 |
Execution timed out |
1066 ms |
25740 KB |
Time limit exceeded |