제출 #500202

#제출 시각아이디문제언어결과실행 시간메모리
500202NartifactMecho (IOI09_mecho)C++17
컴파일 에러
0 ms0 KiB
bool cx[N][N];
pii sta, fin;

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

struct adt {int x, y, step;};

bool ok (const int& tg)
{
    queue <adt> q;
    memset(cx, 0, sizeof cx);
    q.push({sta.fi, sta.se, 0});
    cx[sta.fi][sta.se] = 1;
    while(q.size()) {
        auto tmp = q.front(); q.pop();
        if(tmp.x == fin.fi && tmp.y == fin.se) return 1;
        forinc(i,0,3) {
            int nh = tmp.x + H[i];
            int nc = tmp.y + C[i];
            if(valid(nh, nc) && !cx[nh][nc] && (tmp.step + 1) / s < t[nh][nc] - tg) {
                q.push({nh, nc, tmp.step + 1});
                cx[nh][nc] = 1;
            }
        }
    }
    return 0;
}

void solve ()
{
    queue <pii> q;
    forinc(i,1,n) forinc(j,1,n) {
        t[i][j] = inf;
        if(a[i][j] == 'H') {
            q.push({i, j});
            t[i][j] = 0;
        }
        else if(a[i][j] == 'M') sta = {i, j};
        else if(a[i][j] == 'D') fin = {i, j};
    }

    // bfs bee
    while(q.size()) {
        auto x = q.front(); q.pop();
        forinc(i,0,3) {
            int nh = x.fi + H[i];
            int nc = x.se + C[i];
            if(valid(nh, nc) && t[nh][nc] > t[x.fi][x.se] + 1) {
                t[nh][nc] = t[x.fi][x.se] + 1;
                q.push({nh, nc});
            }
        }
    }
	t[fin.fi][fin.se] = inf;
    // binary search
    int l = 0, r = t[sta.fi][sta.se], ans = -1;
    while(l <= r) {
        int mid = l + r >> 1;
        if(ok(mid)) {
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    cout << ans;
}

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

main ()
{
	#define task "ioi09_mecho"
	cin.tie(0) -> sync_with_stdio(0);
	if(fopen (task ".inp", "r")) {
		freopen (task ".inp", "r", stdin);
		freopen (task ".out", "w", stdout);
	}
    read();
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

mecho.cpp:1:9: error: 'N' was not declared in this scope
    1 | bool cx[N][N];
      |         ^
mecho.cpp:1:12: error: 'N' was not declared in this scope
    1 | bool cx[N][N];
      |            ^
mecho.cpp:2:1: error: 'pii' does not name a type
    2 | pii sta, fin;
      | ^~~
mecho.cpp: In function 'bool valid(const int&, const int&)':
mecho.cpp:6:27: error: 'n' was not declared in this scope
    6 |     return x && y && x <= n && y <= n
      |                           ^
mecho.cpp:7:14: error: 'a' was not declared in this scope
    7 |           && a[x][y] != 'T';
      |              ^
mecho.cpp: In function 'bool ok(const int&)':
mecho.cpp:14:5: error: 'queue' was not declared in this scope
   14 |     queue <adt> q;
      |     ^~~~~
mecho.cpp:14:15: error: expected primary-expression before '>' token
   14 |     queue <adt> q;
      |               ^
mecho.cpp:14:17: error: 'q' was not declared in this scope
   14 |     queue <adt> q;
      |                 ^
mecho.cpp:15:12: error: 'cx' was not declared in this scope
   15 |     memset(cx, 0, sizeof cx);
      |            ^~
mecho.cpp:15:5: error: 'memset' was not declared in this scope
   15 |     memset(cx, 0, sizeof cx);
      |     ^~~~~~
mecho.cpp:1:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
  +++ |+#include <cstring>
    1 | bool cx[N][N];
mecho.cpp:16:13: error: 'sta' was not declared in this scope; did you mean 'std'?
   16 |     q.push({sta.fi, sta.se, 0});
      |             ^~~
      |             std
mecho.cpp:20:21: error: 'fin' was not declared in this scope
   20 |         if(tmp.x == fin.fi && tmp.y == fin.se) return 1;
      |                     ^~~
mecho.cpp:21:16: error: 'i' was not declared in this scope
   21 |         forinc(i,0,3) {
      |                ^
mecho.cpp:21:9: error: 'forinc' was not declared in this scope
   21 |         forinc(i,0,3) {
      |         ^~~~~~
mecho.cpp: In function 'void solve()':
mecho.cpp:35:5: error: 'queue' was not declared in this scope
   35 |     queue <pii> q;
      |     ^~~~~
mecho.cpp:35:12: error: 'pii' was not declared in this scope
   35 |     queue <pii> q;
      |            ^~~
mecho.cpp:35:17: error: 'q' was not declared in this scope
   35 |     queue <pii> q;
      |                 ^
mecho.cpp:36:12: error: 'i' was not declared in this scope
   36 |     forinc(i,1,n) forinc(j,1,n) {
      |            ^
mecho.cpp:36:16: error: 'n' was not declared in this scope
   36 |     forinc(i,1,n) forinc(j,1,n) {
      |                ^
mecho.cpp:36:5: error: 'forinc' was not declared in this scope
   36 |     forinc(i,1,n) forinc(j,1,n) {
      |     ^~~~~~
mecho.cpp:58:2: error: 't' was not declared in this scope
   58 |  t[fin.fi][fin.se] = inf;
      |  ^
mecho.cpp:58:4: error: 'fin' was not declared in this scope
   58 |  t[fin.fi][fin.se] = inf;
      |    ^~~
mecho.cpp:58:22: error: 'inf' was not declared in this scope; did you mean 'int'?
   58 |  t[fin.fi][fin.se] = inf;
      |                      ^~~
      |                      int
mecho.cpp:60:22: error: 'sta' was not declared in this scope; did you mean 'std'?
   60 |     int l = 0, r = t[sta.fi][sta.se], ans = -1;
      |                      ^~~
      |                      std
mecho.cpp:62:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |         int mid = l + r >> 1;
      |                   ~~^~~
mecho.cpp:64:13: error: 'ans' was not declared in this scope
   64 |             ans = mid;
      |             ^~~
mecho.cpp:69:5: error: 'cout' was not declared in this scope
   69 |     cout << ans;
      |     ^~~~
mecho.cpp:69:13: error: 'ans' was not declared in this scope
   69 |     cout << ans;
      |             ^~~
mecho.cpp: In function 'void read()':
mecho.cpp:74:5: error: 'cin' was not declared in this scope
   74 |     cin >> n >> s;
      |     ^~~
mecho.cpp:74:12: error: 'n' was not declared in this scope
   74 |     cin >> n >> s;
      |            ^
mecho.cpp:74:17: error: 's' was not declared in this scope
   74 |     cin >> n >> s;
      |                 ^
mecho.cpp:75:12: error: 'i' was not declared in this scope
   75 |     forinc(i,1,n) forinc(j,1,n)
      |            ^
mecho.cpp:75:5: error: 'forinc' was not declared in this scope
   75 |     forinc(i,1,n) forinc(j,1,n)
      |     ^~~~~~
mecho.cpp: At global scope:
mecho.cpp:80:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   80 | main ()
      | ^~~~
mecho.cpp: In function 'int main()':
mecho.cpp:83:2: error: 'cin' was not declared in this scope
   83 |  cin.tie(0) -> sync_with_stdio(0);
      |  ^~~
mecho.cpp:84:5: error: 'fopen' was not declared in this scope
   84 |  if(fopen (task ".inp", "r")) {
      |     ^~~~~
mecho.cpp:1:1: note: 'fopen' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
  +++ |+#include <cstdio>
    1 | bool cx[N][N];
mecho.cpp:85:30: error: 'stdin' was not declared in this scope
   85 |   freopen (task ".inp", "r", stdin);
      |                              ^~~~~
mecho.cpp:85:30: note: 'stdin' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?
mecho.cpp:85:3: error: 'freopen' was not declared in this scope
   85 |   freopen (task ".inp", "r", stdin);
      |   ^~~~~~~
mecho.cpp:86:30: error: 'stdout' was not declared in this scope
   86 |   freopen (task ".out", "w", stdout);
      |                              ^~~~~~
mecho.cpp:86:30: note: 'stdout' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?