이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
char D[200000];
int U[800][800];
int tt[16];
int parent[640000];
int find(int n) {
if (parent[n] != n) parent[n] = find(parent[n]);
return parent[n];
}
int done[640000];
queue<pii> Q;
int visited[800][800];
int main() {
int i,j;
int M,R,C;
scanf("%d %d %d",&M,&R,&C);
for (i = 0; i < M; i++) scanf(" %c",&D[i]),D[i+M] = D[i];
for (i = 0; i < R; i++) {
for (j = 0; j < C; j++) scanf("%d",&U[i][j]);
}
for (i = 1; i < 16; i++) {
int p = -1;
for (j = 0; j < 2*M; j++) {
int yes;
if (D[j] == 'W') yes = (i & 1);
else if (D[j] == 'N') yes = (i & 2);
else if (D[j] == 'E') yes = (i & 4);
else yes = (i & 8);
if (yes) tt[i] = max(tt[i],j-p);
else p = j;
}
if (tt[i] >= M) tt[i] = 100001;
}
int k,l,f = 1,t = 0;
int best = R*C+1,num = 1;
for (i = 0; i < R*C; i++) parent[i] = i;
while (f) {
f = 0;
for (i = 0; i < R; i++) {
for (j = 0; j < C; j++) {
if ((U[i][j] > 0) && !done[i*C+j] && (find(i*C+j) == i*C+j)) {
int c = 0,mx = -1,my = -1;
visited[i][j] = ++t,Q.push(mp(i,j));
while (!Q.empty()) {
int x = Q.front().second,y = Q.front().first;
Q.pop(),c++;
for (k = 0; k < 4; k++) {
int xx = x+dx[k],yy = y+dy[k];
if ((xx >= 0) && (xx < C) && (yy >= 0) && (yy < R) && (visited[yy][xx] != t) && (U[yy][xx] > 0)) {
int m = 0;
for (l = 0; l < 4; l++) {
int x2 = xx+dx[l],y2 = yy+dy[l];
if ((x2 >= 0) && (x2 < C) && (y2 >= 0) && (y2 < R) && (visited[y2][x2] == t)) m |= (1 << l);
}
if (tt[m] >= U[yy][xx]) {
if (find(yy*C+xx) != i*C+j) mx = xx,my = yy;
visited[yy][xx] = t;
Q.push(mp(yy,xx));
if(mx != -1)break;
}
}
}
if (mx != -1) break;
}
while (!Q.empty()) Q.pop();
if (mx == -1) {
if (c < best) best = num = c;
else if (c == best) num += c;
done[i*C+j] = 1;
}
// else if (done[find(my*C+mx)]) done[i*C+j] = 1;
else parent[i*C+j] = find(my*C+mx);
f = 1;
}
}
}
}
printf("%d\n%d\n",best,num);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
virus.cpp: In function 'int main()':
virus.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&M,&R,&C);
~~~~~^~~~~~~~~~~~~~~~~~~~~
virus.cpp:75:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 0; i < M; i++) scanf(" %c",&D[i]),D[i+M] = D[i];
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
virus.cpp:77:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (j = 0; j < C; j++) scanf("%d",&U[i][j]);
~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |