답안 #834992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834992 2023-08-23T04:50:16 Z maomao90 바이러스 (JOI19_virus) C++17
6 / 100
313 ms 42052 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;
const int MAXR = 805;
const int diri[] = {-1, 0, 1, 0}, dirj[] = {0, 1, 0, -1};

int key[500];

int n, r, c;
string s;
int a[MAXN];
int g[MAXR][MAXR];
int gap[1 << 4];
vii adj[MAXR][MAXR];
bool vis[MAXR][MAXR];
int st[MAXR][MAXR];
int ans, ansc;

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    key['N'] = 0, key['E'] = 1, key['S'] = 2, key['W'] = 3;
    cin >> n >> r >> c;
    cin >> s;
    REP (i, 1, r + 1) {
        REP (j, 1, c + 1) {
            cin >> g[i][j];
        }
    }
    REP (i, 0, n) {
        a[i] = key[s[i]];
    }
    REP (i, n, 2 * n) {
        a[i] = a[i - n];
    }
    REP (msk, 0, 1 << 4) {
        REP (l, 0, n) {
            int r = l;
            while (r - l < n && (msk >> a[r] & 1)) {
                r++;
            }
            if (r - l == n) {
                gap[msk] = INF;
                break;
            }
            mxto(gap[msk], r - l);
            l = r;
        }
        cerr << msk << ": " << gap[msk] << '\n';
    }
    ans = INF;
    REP (i, 1, r + 1) {
        REP (j, 1, c + 1) {
            if (g[i][j] == 0) {
                continue;
            }
            bool bad = 0;
            REP (k, 0, 4) {
                int vi = i + diri[k], vj = j + dirj[k];
                if (g[vi][vj] == 0 || vis[vi][vj]) {
                    continue;
                }
                if (g[vi][vj] <= gap[1 << (k ^ 2)]) {
                    adj[i][j].pb({vi, vj});
                }
            }
            if (adj[i][j].empty()) {
                ans = 1;
            }
        }
    }
    if (ans == 1) {
        REP (i, 1, r + 1) {
            REP (j, 1, c + 1) {
                if (g[i][j] == 0) {
                    continue;
                }
                if (adj[i][j].empty()) {
                    ansc++;
                }
            }
        }
        cout << ans << '\n' << ansc << '\n';
        return 0;
    }
    if (r > 50 || c > 50) {
        REP (i, 1, r + 1) {
            for (int j : {1, c}) {
                if (g[i][j] == 0) {
                    continue;
                }
                REP (j, 1, c + 1) {
                    vis[i][j] = st[i][j] = 0;
                }
                vis[i][j] = 1;
                queue<ii> qu;
                qu.push({i, j});
                int cnt = 0;
                while (!qu.empty()) {
                    auto [ui, uj] = qu.front(); qu.pop();
                    cnt++;
                    REP (k, 0, 4) {
                        int vi = ui + diri[k], vj = uj + dirj[k];
                        if (g[vi][vj] == 0 || vis[vi][vj]) {
                            continue;
                        }
                        st[vi][vj] |= 1 << (k ^ 2);
                        if (g[vi][vj] <= gap[st[vi][vj]]) {
                            vis[vi][vj] = 1;
                            qu.push({vi, vj});
                        }
                    }
                }
                if (mnto(ans, cnt)) {
                    ansc = 0;
                }
                if (ans == cnt) {
                    ansc++;
                }
            }
        }
        cout << ans << ' ' << ans * ansc << '\n';
        return 0;
    }
    REP (i, 1, r + 1) {
        REP (j, 1, c + 1) {
            if (g[i][j] == 0) {
                continue;
            }
            memset(vis, 0, sizeof vis);
            memset(st, 0, sizeof st);
            vis[i][j] = 1;
            queue<ii> qu;
            qu.push({i, j});
            int cnt = 0;
            while (!qu.empty()) {
                auto [ui, uj] = qu.front(); qu.pop();
                cnt++;
                REP (k, 0, 4) {
                    int vi = ui + diri[k], vj = uj + dirj[k];
                    if (g[vi][vj] == 0 || vis[vi][vj]) {
                        continue;
                    }
                    st[vi][vj] |= 1 << (k ^ 2);
                    if (g[vi][vj] <= gap[st[vi][vj]]) {
                        vis[vi][vj] = 1;
                        qu.push({vi, vj});
                    }
                }
            }
            if (mnto(ans, cnt)) {
                ansc = 0;
            }
            if (ans == cnt) {
                ansc++;
            }
        }
    }
    cout << ans << '\n' << ansc << '\n';
    return 0;
}

Compilation message

virus.cpp: In function 'int main()':
virus.cpp:67:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   67 |         a[i] = key[s[i]];
      |                        ^
virus.cpp:93:18: warning: unused variable 'bad' [-Wunused-variable]
   93 |             bool bad = 0;
      |                  ^~~
virus.cpp:129:42: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  129 |                     vis[i][j] = st[i][j] = 0;
      |                                 ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16016 KB Output is correct
2 Correct 63 ms 30836 KB Output is correct
3 Correct 75 ms 37980 KB Output is correct
4 Correct 65 ms 38028 KB Output is correct
5 Correct 51 ms 18088 KB Output is correct
6 Correct 10 ms 18004 KB Output is correct
7 Incorrect 112 ms 42052 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15572 KB Output is correct
2 Correct 9 ms 16468 KB Output is correct
3 Correct 24 ms 19656 KB Output is correct
4 Correct 12 ms 16496 KB Output is correct
5 Correct 16 ms 16468 KB Output is correct
6 Correct 249 ms 19860 KB Output is correct
7 Correct 7 ms 15584 KB Output is correct
8 Correct 20 ms 19796 KB Output is correct
9 Correct 149 ms 18932 KB Output is correct
10 Correct 12 ms 16468 KB Output is correct
11 Correct 8 ms 15700 KB Output is correct
12 Correct 313 ms 18964 KB Output is correct
13 Correct 193 ms 19848 KB Output is correct
14 Correct 14 ms 16708 KB Output is correct
15 Correct 188 ms 19796 KB Output is correct
16 Correct 13 ms 16596 KB Output is correct
17 Correct 132 ms 19284 KB Output is correct
18 Correct 145 ms 18984 KB Output is correct
19 Correct 14 ms 16596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16016 KB Output is correct
2 Correct 63 ms 30836 KB Output is correct
3 Correct 75 ms 37980 KB Output is correct
4 Correct 65 ms 38028 KB Output is correct
5 Correct 51 ms 18088 KB Output is correct
6 Correct 10 ms 18004 KB Output is correct
7 Incorrect 112 ms 42052 KB Output isn't correct
8 Halted 0 ms 0 KB -