이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define x first
#define y second
const ll INF = 1e18;
ll N, M, K, U[805][805]; string S;
ll Mx[16], App[100005];
ll f(char c){
if(c == 'N') return 0;
if(c == 'S') return 1;
if(c == 'W') return 2;
if(c == 'E') return 3;
}
ll g(vector<ll> &V){
ll r = 0;
for(ll i = 0; i < 4; i++){
if(V[i]) r |= (1 << i);
}
return r;
}
void init(){
string T = S;
while(S.size() <= 100000){
for(auto e : T) S.push_back(e);
}
for(ll k = 0; k < 16; k++){
ll pv = -1;
for(ll i = 0; i < S.size(); i++){
if(!(k & (1 << f(S[i])))){
Mx[k] = max(Mx[k], i - pv - 1); pv = i;
}
}
if(pv == -1) Mx[k] = 100000;
App[Mx[k]] |= (1 << k);
}
for(ll i = 100000; i >= 1; i--){
App[i - 1] |= App[i];
}
}
bool In(ll x, ll y) { return (1 <= x && x <= N && 1 <= y && y <= M); }
ll Vir[805][805], F[805][805];
ll dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
bool chk(ll x, ll y){
ll b = 0;
for(ll i = 0; i < 4; i++){
ll nx = x + dx[i], ny = y + dy[i];
if(In(nx, ny) && Vir[nx][ny]) b |= (1 << i);
}
if(App[U[x][y]] & (1 << b)) return 1;
return 0;
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> K >> N >> M >> S;
vector<pair<ll, ll>> V;
for(ll i = 1; i <= N; i++){
for(ll j = 1; j <= M; j++){
cin >> U[i][j];
V.push_back({i, j});
}
}
init();
ll mn = 1e18, cnt = 0;
random_shuffle(V.begin(), V.end());
for(ll t = 0; t < V.size(); t++){
ll p = V[t].x, q = V[t].y;
if(U[p][q] == 0) continue;
fill(Vir[0], Vir[804] + 805, 0LL);
queue<pair<ll, ll>> Q;
Q.push({p, q});
Vir[p][q] = F[p][q] = 1;
ll Res = 1, bk = 0;
while(!Q.empty()){
ll x = Q.front().x, y = Q.front().y; Q.pop();
for(ll i = 0; i < 4; i++){
ll nx = x + dx[i], ny = y + dy[i];
if(!In(nx, ny) || U[nx][ny] == 0 || !chk(nx, ny) || Vir[nx][ny]) continue;
Vir[nx][ny] = 1; Res++;
Q.push({nx, ny});
if(F[nx][ny]){
bk = 1; break;
}
}
if(bk) break;
}
if(bk) continue;
if(mn > Res){
mn = Res, cnt = Res;
} else if(mn == Res){
cnt += Res;
}
}
cout << mn << '\n' << cnt;
}
컴파일 시 표준 에러 (stderr) 메시지
virus.cpp: In function 'void init()':
virus.cpp:33:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(ll i = 0; i < S.size(); i++){
| ~~^~~~~~~~~~
virus.cpp: In function 'int main()':
virus.cpp:74:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(ll t = 0; t < V.size(); t++){
| ~~^~~~~~~~~~
virus.cpp: In function 'll f(char)':
virus.cpp:17:1: warning: control reaches end of non-void function [-Wreturn-type]
17 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |