답안 #236179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236179 2020-05-31T12:51:47 Z nicolaalexandra Mecho (IOI09_mecho) C++14
97 / 100
405 ms 8696 KB
#include <bits/stdc++.h>
#define DIM 810
using namespace std;

char s[DIM];
int a[DIM][DIM],b[DIM][DIM],dist[DIM][DIM],f[DIM];
deque <pair<int,int> > c,aux,d;
int di[] = {-1,1,0,0};
int dj[] = {0,0,-1,1};
int n,nr,i,j,xstart,ystart,xfin,yfin;
inline int inmat (int i, int j){
    if (i >= 1 && j >= 1 && i <= n && j <= n)
        return 1;
    return 0;
}
int verif (int val){

    /// mai intai vad cat se extind albinele dupa val secunde
    c.clear();
    memset (f,0,sizeof f);
    for (i=1;i<=n;i++)
        for (j=1;j<=n;j++){
            b[i][j] = a[i][j];
            if (a[i][j] == 1)
                c.push_back(make_pair(i,j));
        }

    for (i=1;i<=val;i++){
        aux.clear();
        for (auto it : c){
            int ic = it.first, jc = it.second;
            for (int dir=0;dir<=3;dir++){
                int iv = ic + di[dir];
                int jv = jc + dj[dir];
                if (inmat (iv,jv) && b[iv][jv] == 0){
                    aux.push_back(make_pair(iv,jv));
                    b[iv][jv] = 1;
                }}}
        c = aux;
        f[i] = 1;
    }

    if (b[xstart][ystart])
        return 0;

    /// d - lista cu toate locurile in care pot sa ajung pana la secunda asta
    memset (dist,0,sizeof dist);
    d.clear();
    d.push_back(make_pair(xstart,ystart));
    dist[xstart][ystart] = 1;

    while (!d.empty()){
        int ic = d.front().first;
        int jc = d.front().second;
        d.pop_front();

        if (dist[ic][jc] % nr == 0 && !f[dist[ic][jc] / nr + val]){
            /// inseamna ca a mai trecut un minut si trb sa avansez cu albinele
            f[dist[ic][jc] / nr + val] = 1;
            aux.clear();
            for (auto it : c){
                int i = it.first, j = it.second;
                for (int dir=0;dir<=3;dir++){
                    int iv = i + di[dir];
                    int jv = j + dj[dir];
                    if (inmat(iv,jv) && b[iv][jv] == 0){
                        aux.push_back(make_pair(iv,jv));
                        b[iv][jv] = 1;
                    }}}
            c = aux;
        }

        for (int dir=0;dir<=3;dir++){
            int iv = ic + di[dir];
            int jv = jc + dj[dir];
            if (inmat (iv,jv) && (b[iv][jv] == 0 || b[iv][jv] == 3) && !dist[iv][jv]){
                if (iv == xfin && jv == yfin) /// am reusit sa ajung
                    return 1;

                dist[iv][jv] = 1 + dist[ic][jc];
                d.push_back(make_pair(iv,jv));
            }}}

    return 0;

}


int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n>>nr;
    for (i=1;i<=n;i++){
        cin>>s+1;
        for (j=1;j<=n;j++){
            if (s[j] == 'T')
                a[i][j] = 2;
            if (s[j] == 'M'){
                xstart = i, ystart = j;
                //a[i][j] = 4;
            }
            if (s[j] == 'D'){
                xfin = i, yfin = j;
                a[i][j] = 3;
            }
            if (s[j] == 'H')
                a[i][j] = 1;
        }
    }
    /*for (i=1;i<=n;i++,cout<<endl)
        for (j=1;j<=n;j++)
            cout<<a[i][j]<<" ";
*/
    int st = 0, dr = n*n, sol = -1;
    while (st <= dr){
        int mid = (st+dr)>>1;
        if (verif (mid)){
            sol = mid;
            st = mid+1;
        } else dr = mid-1;
    }

    cout<<sol;

    return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:96:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         cin>>s+1;
              ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Correct 6 ms 2944 KB Output is correct
3 Correct 6 ms 2944 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
5 Correct 6 ms 2944 KB Output is correct
6 Correct 6 ms 2944 KB Output is correct
7 Correct 365 ms 7492 KB Output is correct
8 Correct 6 ms 3072 KB Output is correct
9 Correct 6 ms 2992 KB Output is correct
10 Correct 6 ms 3072 KB Output is correct
11 Correct 6 ms 2944 KB Output is correct
12 Correct 7 ms 3328 KB Output is correct
13 Correct 7 ms 3200 KB Output is correct
14 Correct 8 ms 3328 KB Output is correct
15 Correct 6 ms 2944 KB Output is correct
16 Correct 6 ms 3072 KB Output is correct
17 Correct 8 ms 3072 KB Output is correct
18 Correct 6 ms 3072 KB Output is correct
19 Correct 7 ms 3072 KB Output is correct
20 Correct 6 ms 3072 KB Output is correct
21 Correct 7 ms 3072 KB Output is correct
22 Correct 7 ms 3200 KB Output is correct
23 Correct 7 ms 3200 KB Output is correct
24 Correct 7 ms 3200 KB Output is correct
25 Correct 8 ms 3200 KB Output is correct
26 Correct 8 ms 3328 KB Output is correct
27 Correct 8 ms 3200 KB Output is correct
28 Correct 8 ms 3328 KB Output is correct
29 Correct 8 ms 3328 KB Output is correct
30 Correct 8 ms 3328 KB Output is correct
31 Correct 9 ms 3328 KB Output is correct
32 Correct 8 ms 3328 KB Output is correct
33 Correct 70 ms 4992 KB Output is correct
34 Correct 53 ms 5120 KB Output is correct
35 Correct 57 ms 5112 KB Output is correct
36 Correct 91 ms 5368 KB Output is correct
37 Correct 70 ms 5376 KB Output is correct
38 Correct 70 ms 5368 KB Output is correct
39 Correct 103 ms 5632 KB Output is correct
40 Correct 87 ms 5760 KB Output is correct
41 Correct 91 ms 5752 KB Output is correct
42 Correct 135 ms 6016 KB Output is correct
43 Correct 107 ms 6016 KB Output is correct
44 Correct 146 ms 6136 KB Output is correct
45 Correct 187 ms 6392 KB Output is correct
46 Correct 135 ms 6520 KB Output is correct
47 Correct 132 ms 6392 KB Output is correct
48 Correct 197 ms 6776 KB Output is correct
49 Correct 161 ms 6904 KB Output is correct
50 Correct 164 ms 6780 KB Output is correct
51 Correct 225 ms 7032 KB Output is correct
52 Correct 186 ms 7032 KB Output is correct
53 Correct 187 ms 7032 KB Output is correct
54 Correct 277 ms 7388 KB Output is correct
55 Correct 220 ms 7416 KB Output is correct
56 Correct 220 ms 7416 KB Output is correct
57 Correct 299 ms 7784 KB Output is correct
58 Correct 238 ms 7676 KB Output is correct
59 Correct 245 ms 7928 KB Output is correct
60 Correct 375 ms 8024 KB Output is correct
61 Correct 275 ms 8184 KB Output is correct
62 Correct 296 ms 7928 KB Output is correct
63 Incorrect 396 ms 8056 KB Output isn't correct
64 Correct 404 ms 8036 KB Output is correct
65 Incorrect 395 ms 8056 KB Output isn't correct
66 Incorrect 390 ms 8032 KB Output isn't correct
67 Correct 374 ms 8056 KB Output is correct
68 Correct 355 ms 8056 KB Output is correct
69 Correct 329 ms 8056 KB Output is correct
70 Correct 323 ms 8056 KB Output is correct
71 Correct 358 ms 8056 KB Output is correct
72 Correct 367 ms 8184 KB Output is correct
73 Correct 313 ms 8568 KB Output is correct
74 Correct 374 ms 8568 KB Output is correct
75 Correct 405 ms 8696 KB Output is correct
76 Correct 380 ms 8696 KB Output is correct
77 Correct 379 ms 8568 KB Output is correct
78 Correct 387 ms 8568 KB Output is correct
79 Correct 386 ms 8516 KB Output is correct
80 Correct 393 ms 8568 KB Output is correct
81 Correct 394 ms 8568 KB Output is correct
82 Correct 396 ms 8440 KB Output is correct
83 Correct 385 ms 8440 KB Output is correct
84 Correct 390 ms 8380 KB Output is correct
85 Correct 395 ms 8440 KB Output is correct
86 Correct 384 ms 8568 KB Output is correct
87 Correct 382 ms 8428 KB Output is correct
88 Correct 379 ms 8440 KB Output is correct
89 Correct 378 ms 8440 KB Output is correct
90 Correct 372 ms 8440 KB Output is correct
91 Correct 384 ms 8444 KB Output is correct
92 Correct 384 ms 8440 KB Output is correct