답안 #1097074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097074 2024-10-06T03:13:03 Z InvMOD Mecho (IOI09_mecho) C++14
38 / 100
140 ms 7032 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
///#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}

const int N = 8e2+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

int n, s, d[N][N], vis[N][N];
char a[N][N];

bool init(int x, int y){
    return (x >= 1 && x <= n) && (y >= 1 && y <= n) && a[x][y] != 'T';
}

bool good(int time){
    pi st, ed;
    FOR(i, 1, n){
        FOR(j, 1, n){
            if(a[i][j] == 'M'){
                st = make_pair(i,j);
                vis[i][j] = time*s;
            }
            else{
                if(a[i][j] == 'D'){
                    ed = make_pair(i, j);
                }
                vis[i][j] = n*n + time*s;
            }
        }
    }

    if((time / s) + (time % s != 0) > d[st.fi][st.se]) return false;

    queue<pair<int,int>> q;
    q.push(st);

    while(sz(q)){
        pi e = q.front(); q.pop();

        int x = e.fi, y = e.se;
        for(int i = 0; i < 4; i++){
            int xx = x + dx[i];
            int yy = y + dy[i];
            if(init(xx, yy) && vis[xx][yy] == n*n + time*s && a[xx][yy] != 'H'){
                int n_dist = (vis[x][y] + 1) / s + ((vis[x][y]+1) % s != 0);
                if(n_dist <= d[xx][yy]){
                    vis[xx][yy] = vis[x][y] + 1;
                    q.push(make_pair(xx, yy));
                }
            }
        }
    }

    return vis[ed.fi][ed.se] != n*n + time*s;
}

void solve()
{
    cin >> n >> s;
    FOR(i, 1, n){
        FOR(j, 1, n){
            cin >> a[i][j];
        }
    }

    queue<pair<int,int>> q;

    FOR(i, 1, n){
        FOR(j, 1, n){
            if(a[i][j] == 'H'){
                q.push(make_pair(i,j));
            }
            else d[i][j] = n*n;
        }
    }

    while(sz(q)){
        pi e = q.front(); q.pop();

        int x = e.fi, y = e.se;
        for(int i = 0; i < 4; i++){
            int xx = x + dx[i];
            int yy = y + dy[i];
            if(init(xx, yy) && d[xx][yy] == n*n && a[xx][yy] != 'D'){
                d[xx][yy] = d[x][y] + 1;
                q.push(make_pair(xx, yy));
            }
        }
    }

    //cout << good(2) <<"\n"; return;


    int l = -1, r = n*n+1;
    while(l+1 < r){
        int m = l+r>>1;
        if(good(m)){
            l = m;
        }
        else r = m;
    }
    cout << l <<"\n";
}

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

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP","r",stdin);
        freopen(name".OUT","w",stdout);
    }

    int t = 1; //cin >> t;
    while(t--) solve();
    return 0;
}

Compilation message

mecho.cpp: In function 'void solve()':
mecho.cpp:117:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  117 |         int m = l+r>>1;
      |                 ~^~
mecho.cpp: In function 'int main()':
mecho.cpp:134:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  134 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:135:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |         freopen(name".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 352 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 75 ms 6668 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 860 KB Output isn't correct
13 Incorrect 1 ms 860 KB Output isn't correct
14 Correct 1 ms 860 KB Output is correct
15 Incorrect 0 ms 604 KB Output isn't correct
16 Correct 0 ms 604 KB Output is correct
17 Incorrect 0 ms 604 KB Output isn't correct
18 Correct 0 ms 604 KB Output is correct
19 Incorrect 0 ms 604 KB Output isn't correct
20 Correct 0 ms 604 KB Output is correct
21 Incorrect 1 ms 604 KB Output isn't correct
22 Correct 1 ms 724 KB Output is correct
23 Incorrect 0 ms 604 KB Output isn't correct
24 Correct 0 ms 604 KB Output is correct
25 Incorrect 1 ms 856 KB Output isn't correct
26 Correct 1 ms 860 KB Output is correct
27 Incorrect 1 ms 860 KB Output isn't correct
28 Correct 1 ms 860 KB Output is correct
29 Incorrect 1 ms 860 KB Output isn't correct
30 Correct 1 ms 856 KB Output is correct
31 Incorrect 1 ms 860 KB Output isn't correct
32 Correct 1 ms 860 KB Output is correct
33 Incorrect 6 ms 3160 KB Output isn't correct
34 Correct 6 ms 2908 KB Output is correct
35 Correct 16 ms 3076 KB Output is correct
36 Incorrect 8 ms 3420 KB Output isn't correct
37 Correct 7 ms 3420 KB Output is correct
38 Correct 20 ms 3476 KB Output is correct
39 Incorrect 8 ms 3676 KB Output isn't correct
40 Correct 9 ms 3672 KB Output is correct
41 Correct 28 ms 3860 KB Output is correct
42 Incorrect 10 ms 4188 KB Output isn't correct
43 Correct 10 ms 4188 KB Output is correct
44 Correct 35 ms 4244 KB Output is correct
45 Incorrect 12 ms 4444 KB Output isn't correct
46 Correct 15 ms 4440 KB Output is correct
47 Correct 38 ms 4440 KB Output is correct
48 Incorrect 14 ms 4956 KB Output isn't correct
49 Correct 14 ms 4956 KB Output is correct
50 Correct 47 ms 4956 KB Output is correct
51 Incorrect 17 ms 5468 KB Output isn't correct
52 Correct 17 ms 5468 KB Output is correct
53 Correct 63 ms 5468 KB Output is correct
54 Incorrect 19 ms 5724 KB Output isn't correct
55 Correct 25 ms 5908 KB Output is correct
56 Correct 67 ms 5720 KB Output is correct
57 Incorrect 22 ms 6236 KB Output isn't correct
58 Correct 22 ms 6232 KB Output is correct
59 Correct 76 ms 6232 KB Output is correct
60 Incorrect 26 ms 6744 KB Output isn't correct
61 Correct 29 ms 6748 KB Output is correct
62 Correct 89 ms 6744 KB Output is correct
63 Correct 79 ms 6748 KB Output is correct
64 Correct 140 ms 6748 KB Output is correct
65 Correct 108 ms 6748 KB Output is correct
66 Incorrect 101 ms 6748 KB Output isn't correct
67 Correct 84 ms 6744 KB Output is correct
68 Correct 43 ms 6744 KB Output is correct
69 Correct 42 ms 6736 KB Output is correct
70 Correct 35 ms 6824 KB Output is correct
71 Correct 37 ms 6768 KB Output is correct
72 Incorrect 32 ms 6748 KB Output isn't correct
73 Incorrect 36 ms 7004 KB Output isn't correct
74 Correct 45 ms 7032 KB Output is correct
75 Correct 57 ms 7000 KB Output is correct
76 Correct 48 ms 7000 KB Output is correct
77 Correct 50 ms 6996 KB Output is correct
78 Correct 57 ms 7004 KB Output is correct
79 Correct 41 ms 7004 KB Output is correct
80 Correct 48 ms 7000 KB Output is correct
81 Correct 53 ms 7004 KB Output is correct
82 Correct 50 ms 6968 KB Output is correct
83 Correct 63 ms 6744 KB Output is correct
84 Correct 58 ms 6740 KB Output is correct
85 Correct 61 ms 6968 KB Output is correct
86 Correct 58 ms 6744 KB Output is correct
87 Correct 57 ms 6748 KB Output is correct
88 Correct 63 ms 6736 KB Output is correct
89 Correct 62 ms 6748 KB Output is correct
90 Correct 66 ms 6700 KB Output is correct
91 Correct 64 ms 6744 KB Output is correct
92 Correct 66 ms 6748 KB Output is correct